jQuery的复选框改变功能的IE 8不工作 [英] Jquery check box change function not working in IE 8

查看:232
本文介绍了jQuery的复选框改变功能的IE 8不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的jquery code,其中一个复选框点击我将展示一个弹出值。

除了在IE浏览器,在它按预期工作的所有其他浏览器。也就是说,在变化的复选框将被选中并弹出将被打开。

然而,在IE8其没有得到遏制,但弹出窗口正常显示。

code:

  $('#TAndC')。改变(函数(){    如果($('输入[名称=TAndC]')是(':检查'))
    {
         $('#TandCBox)显示()。
         VAR termsandcondition = GetEnum()TermsandConditionsPageId。
         VAR actionURL ='@ Url.Action(ShowTAndC,帐户,新的{isFromCheckBox =真});
         $('。PopupForm类')负载(actionURL)。
         VAR MSGBOX = $('#条款)ATTR('href属性)。
         MaskMsgPopUp(MSGBOX);
         返回false;
     }
});


解决方案

如果你的元素是复选框,而不是下拉菜单然后用点击反正。

如果你的选择是指 A 下拉菜单中使用点击如果您需要支持IE8及以上。

明白为什么这是下文。

按照 MSDN改变/的onchange ,则不会触发事件,直到提交了更改。

另外,当值编程方式更改,也不会触发事件。

要报价:


  

在内容都致力于此事件被触发,而不是当
  值发生变化。例如,在一个文本框,不触发此​​事件
  而用户打字,而是当用户提交更改
  留下具有焦点的文本框。此外,本次活动是
  当控制也是由指定的onblur的code之前执行
  失去焦点。当选择的onchange事件不会触发
  选择对象的选项被编程改变。修改后的文本
  选择承诺。


  
  

要调用此事件,请执行下列操作之一:


  
  

      
  • 选择使用鼠标或键盘导航在选择对象不同的选项。

  •   
  • 在文本区域阿尔特文本,然后从导航的对象。

  •   

如果您必须支持IE8及以上,你可能会更好的使用点击事件,而不是它获得,当你松开鼠标并选择您的新选择的触发。

I have following jquery code, where on click of a check box I will show a popup value.

Except in IE,in all other browser it works as expected. That is, on change the check box will be checked and the popup will be opened.

However in IE8 its not getting checked, however popup is displayed properly.

Code :

$('#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;
     }
});

解决方案

If your element is a checkbox and not a dropdown then use click anyway.

If your selector is referring to a dropdown use click if you need to support IE8 and older.

See why that is below.

According to the MSDN for change/onchange, the event is not triggered until the change is committed.

In addition the event is also not triggered when the value is changed programmatically.

To quote:

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.

If you must support IE8 and older, you are probably better of to use the click event instead which get's triggered when you release the mouse and your new choice is selected.

这篇关于jQuery的复选框改变功能的IE 8不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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