【发布时间】:2011-11-04 06:02:11
【问题描述】:
在我的表单中,我有一个CheckBox,并且我有一个 CheckBox 的标签。在 Firefox 和 IE9 中,CheckBox 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>
我的 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();
}
});
【问题讨论】:
-
你有什么版本的jquery?
-
根据本文档api.jquery.com/change:“从 jQuery 1.4 开始,更改事件在 Internet Explorer 中冒泡,其行为与其他现代浏览器中的事件一致。”考虑更改 jquery 版本。
-
如果有帮助请告诉我们
-
hmmm............我将“更改”事件更改为“点击”事件,现在它可以工作了,谢谢大家
-
只是一个提示 - 不要在此处粘贴代码,将其添加到 jsfiddle 并给我们链接。活生生的例子更好。
标签: javascript jquery html css