javascript - Jquery 复选框更改功能在 IE 8 中不起作用

标签 javascript jquery asp.net-mvc internet-explorer checkbox

我有以下 jquery 代码,单击复选框时将显示一个弹出值。

除了 IE 之外,在所有其他浏览器中它都按预期工作。也就是说,在更改时,将选中复选框并打开弹出窗口。

但是在 IE8 中它不会被检查,但是弹出窗口会正确显示。

代码:

$('#TAndC').change(function(){

    if( $('input[name="TAndC"]').is(':checked')) 
    {
         $('#TandCBox').show();
         var termsandcondition = GetEnum().TermsandConditionsPageId;
         var actionURL = '@Url.Action("ShowTAndC", "Account", new { isFromCheckBox = true })';
         $('.popUpForm').load(actionURL);
         var msgBox = $('#terms').attr('href');
         MaskMsgPopUp(msgBox);
         return false;
     }
});

最佳答案

如果您的元素是复选框而不是下拉列表,那么无论如何都要使用click

如果您的选择器引用下拉,并且您需要支持 IE8 及更早版本,请使用click

看看下面的原因。

根据MSDN for change/onchange ,直到提交更改后才会触发该事件。

此外,当以编程方式更改值时,也不会触发该事件。

引用:

This event is fired when the contents are committed and not while the value is changing. For example, on a text box, this event is not fired while the user is typing, but rather when the user commits the change by leaving the text box that has focus. In addition, this event is executed before the code specified by onblur when the control is also losing the focus. The onchange event does not fire when the selected option of the select object is changed programmatically. Changed text selection is committed.

To invoke this event, do one of the following:

  • Choose a different option in a select object using mouse or keyboard navigation.
  • Alter text in the text area and then navigate out of the object.

如果您必须支持 IE8 及更早版本,您可能最好使用 click 事件,而不是在释放鼠标并选择新选项时触发该事件。

关于javascript - Jquery 复选框更改功能在 IE 8 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20679835/

相关文章:

javascript - 如何使用 javascript scrollIntoView() 转到 id ,并在页面中间?

javascript - 使用 jQuery 删除某些字段

javascript - 您将如何调整我的递归硬币总和算法解决方案?

javascript - Paulo P. Marinas 的 jQuery AlphaNumeric - 不会禁止某些字符

javascript - 如何在 Angular 6 中使用 Amcharts 4?

javascript - 如何更改包含文本的框,使其仅包含颜色?

jquery - 像teehan+lax网站那样隐藏滚动条

asp.net-mvc - Entity Framework 更新实体以及子实体(根据需要添加/更新)

c# - 非通用声明不允许约束

asp.net-mvc - 带有接口(interface)的 ASP.NET MVC UpdateModel