复选框& # 39;改变# 39;事件在单击标签时起作用.ie8, ie7
Checkbox 'change' event works when click the label . in ie8, ie7
在我的表单中,我有一个CheckBox
,我有一个标签CheckBox。在firefox &在IE9中,复选框change event
按预期工作,但在IE8中;在IE7中,当单击标签而不是复选框时触发事件。
HTML
<div class="item-container">
<div class="label-container">
</div>
<div class="textbox-container">
<input id="AddNewProductCategory" class="" type="checkbox" width="20px" height="20px"
value="1" name="addnewproductcategory" tabindex="1900" />
</div>
<div class="after-checkbox-label">
<label class="Verdana11-424039" for="AddNewProductCategory">
Add New Service Category</label>
</div>
</div>
My jQuery
jq('#AddNewProductCategory').change(function(){
jq('#CategoryName').next('label[for=CategoryName]').remove();
jq('#Category').next('label[for=Category]').remove();
if (!jq('#AddNewProductCategory').is(':checked')) {
alert("in change");
jq('input[name="newcategory"]').val('');
jq('#CategoryName').hide();
jq('#store_category').hide();
jq('#Category').removeAttr('disabled');
}
else {
jq('#Category').attr('disabled', 'disabled');
jq('#CategoryName').show();
jq('#store_category').show();
}
});
仅供将来参考,据我所知,"change"事件在旧版本的IE中有点错误。
你必须使用propertychange
事件在IE中得到它的行为如预期的。我喜欢使用的代码是:
Edit 2 (back to core)
$(element).on(navigator.userAgent.match(/msie/i) ? "propertychange" : "change", function(evt) {
evt.preventDefault();
// Your code here
});
编辑1(有bug,不可靠)
$(element).on(!$.support.changeBubbles ? "propertychange" : "change", function(evt) {
evt.preventDefault();
// Your code here
});
此代码已更新为使用jQuery 1.9+,并在注释中使用马吕斯的一些输入。
原始(弃用)以下是使用旧版本jQ的旧代码:
$(element).bind($.browser.msie ? 'propertychange' : 'change', function(evt) {
evt.preventDefault();
// Your code here
});
相关文章:
- Recaptcha在IE7和IE8中不起作用
- 在IE8中不起作用的元素上触发单击事件
- 数据-在IE8中不起作用
- getComputedStyle替换:currentStyle(IE8/7)不起作用
- IE8 jquery ajax头请求不起作用
- 显示隐藏的html表在javascript(IE8)中不起作用
- ScriptX 打印功能在 IE8 中不起作用
- Angularjs 跨源资源共享 (CORS) 发布或放置方法在 IE8 和 IE9 中不起作用
- ExtJs 5.0:forEach on Array of Objects在IE8中不起作用
- 将JSON对象转换为敲除observable在IE8中不起作用,但在所有其他浏览器中都起作用
- 聚焦函数在ie8中不起作用
- 启动网格在IE8中不起作用
- Svg标签在IE8中不起作用
- Twitter引导程序示例在IE8中不起作用
- 引导程序3在IE8中不起作用(已检查其他答案)
- IE8的Javascript占位符不起作用
- Javascript中的开关案例在IE8中不起作用
- $.getScript 不起作用 (IE8)
- 点击事件不起作用IE8
- 复选框& # 39;改变# 39;事件在单击标签时起作用.ie8, ie7