OnChange not firing in IE

后端 未结 7 1245
我在风中等你
我在风中等你 2020-12-04 01:40

I wish to fire a Onchange event for all the changes of Form elements within a DIV

Here\'s the snippet




相关标签:
7条回答
  • 2020-12-04 02:01

    Avoid using .focus() or .select() before .change() function of jquery for IE, then it works fine, im using it in my site.

    Thanks

    0 讨论(0)
  • 2020-12-04 02:06

    onchange event does not bubble in IE according to MSDN.

    0 讨论(0)
  • 2020-12-04 02:09

    Actually, IE, especially IE7/8 doesn't support onchange event very well . I do recommend you use onclick event.

    0 讨论(0)
  • 2020-12-04 02:14

    Actually Onchange does not work very well in IE. Here is what I did while using Javascript. You can replicate it accordingly.

    1. Add ondrop event in HTML to call the function being called now, instead of onchange.
    2. Add the following code in your js file

      document.getElementById('--your selector--').ondragover = handle;
      
      function handle(evt)
      {
           evt.stopPropagation();
           evt.preventDefault();
           evt.dataTransfer.dropEffect = 'copy'
      }
      
    3. The ondragover will be made false by above code, and then ondrop will fire on all browsers and call the required function

    0 讨论(0)
  • 2020-12-04 02:18

    Mostly all web developer must have faced this issue.. yeh the older version of IE sometimes not firing the onChange event and replacing it with onClick works.

    But this is not expected with latest IE 11. what I found in my case was the function name being called on onChange event was clashing somewhere. I just changed it to some other name which should sound like unique in the whole context, then it worked.

    Conclusion: IE 11 getting confused when finds some similar names within the system matching with the onchange target function (even the file names I guess), while the other browsers are intelligent enough.

    0 讨论(0)
  • 2020-12-04 02:19

    I created this code to trigger the onchange event not triggered by Interenet Explorer.

    Used with an asp.net textbox

    <!-- LOCAL SCRIPT -->
    <script type="text/javascript">
    $(document).ready(function () {
    
      // CTRL - fix explorer bug for OnChange not triggered. Converted to OnBlur + test
      if (navigator.appName == 'Microsoft Internet Explorer')
      {
        var tempControl = $("#<%= textboxNAME.ClientID %>");
        var tempATTRIBUTE = "data-lastvalue";
        // GET - save current value inside attribute
        tempControl.attr(tempATTRIBUTE, tempControl.val());
        // BIND - onblur event
        $("#<%= textboxNAME.ClientID %>").blur(function () {
            var tempPrevValue = tempControl.attr(tempATTRIBUTE);
            // CTRL - is there a difference of value (onchange)
            if (tempControl.val() != tempPrevValue) {
                // SET - trigger change js binded to textbox
                $(this).change();
            }
            });
      }
    
    
    });
    
    
    0 讨论(0)
提交回复
热议问题