最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - triggering input file click in IE9 - Stack Overflow

programmeradmin1浏览0评论

I can't seem to trigger the click event of input file in IE and i don't know what is the problem

<input type="file" class="ruFileInput" />
<button id="clickMe" value="ClickMe" ></button>


<script type="text/javascript">
   $(document).ready(function(){
      $("#clickMe").click(function(){
         $('input[type=file]').trigger('click');
      });
   });

it's working fine on firfox and chrome but not in IE9

I can't seem to trigger the click event of input file in IE and i don't know what is the problem

<input type="file" class="ruFileInput" />
<button id="clickMe" value="ClickMe" ></button>


<script type="text/javascript">
   $(document).ready(function(){
      $("#clickMe").click(function(){
         $('input[type=file]').trigger('click');
      });
   });

it's working fine on firfox and chrome but not in IE9

Share Improve this question edited Mar 3, 2013 at 16:28 Josh Unger 7,2037 gold badges37 silver badges55 bronze badges asked Aug 31, 2012 at 12:10 SoraSora 2,55119 gold badges77 silver badges151 bronze badges 1
  • works in ie ? jsfiddle/QTWDd – anderssonola Commented Aug 31, 2012 at 12:14
Add a ment  | 

2 Answers 2

Reset to default 3

Add the closing quotes to the class of the first input and add some text to the button to show properly

Here is a fiddle that worked

Also make sure you are grabbing the jquery files as well in your html

Just tested the below and it worked fine. You had missed the closing " at the end of class="ruFileInput

I have tested on IE9 and works fine.

<html>
<head>
<script src="http://ajax.googleapis./ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $("#clickMe").click(function(){
            $('input[type=file]').trigger('click');
        });
    });
</script>
</head>
<body>
   <input type="file" class="ruFileInput" />
   <button id="clickMe" value="ClickMe" ></button>
</body>
</html>
发布评论

评论列表(0)

  1. 暂无评论