。在IE9中表现怪异 [英] .change acting weird in IE9

查看:127
本文介绍了。在IE9中表现怪异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


$ b

 < button>编辑照片< / button> 
< form style =visibility:hidden;>
< input type =fileid =filename =fileval =/>
< input type =submitname =submit>
< / form>

和我的javascript看起来像这样



<$ p ();
$(#file)。click();
}); $ p $ $(#edit-button

$(#file)。change(function(){
// submit form
});

起初我以为IE9可能不会识别Jquery中的.change事件,但我注意到如果取消隐藏我的表单并直接点击它,更改函数被触发。如果我使用编辑按钮来激活浏览,那么.change即使更改也不起作用。



我猜,当我点击浏览文件输入按钮,它不会像$(#file)那样读取。click()。任何人都知道一种方法来解决这个问题?

我正在猜测因为你的处理程序没有被绑定到不可见的形式(这是有时)。

p> //文档或其他容器
$(document).on(change,#file,function(){
//提交表单
});


So I have a form submit set up like this

<button>edit a photo</button>
<form style="visibility: hidden;">
  <input type="file" id="file" name="file" val=""/>
  <input type="submit" name="submit">
</form>

and my javascript looks like this

$("#edit-button").click(function() {
  $("#file").click();
});

$("#file").change(function() {
  //submit form
});

At first I thought that perhaps IE9 wasn't recognizing the .change event from Jquery, however I noticed that if unhide my form and click it directly the change function is fired. If I use the edit button to activate the browse then the .change doesn't work even through it is changed.

I'm guess that when I click the "browse" button for the file input it doesn't get read the same as just $("#file").click(). Anyone know a way to remedy this?

解决方案

I'm guessing that is happening because your handlers are not being bound to the invisible form (this is the case, sometimes).

Try:

// document or some other container
$(document).on("change", "#file", function () {
    //submit form
});

这篇关于。在IE9中表现怪异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆