“onchange” event not firing in Safari family browsers(for a fieldset)

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-08 10:10:38

问题


I know that I should use its alternative "onclick" for "checkboxes", to overcome this problem in "Safari" and "Chrome". But what should I do if I want to use an "onchange" event for a "fieldset" (a group of checkboxes)?


回答1:


It seems that assigning "onchange" event after page load using "javascript" , works! Here is an example:

<script type="text/javascript">


      window.onload = function() {

            var fieldsets = document.getElementsByTagName("fieldset");
            for( i = 0 ; i < fieldsets.length ; i++ ) {

                  fieldsets[i].onchange = function() {

                         Validate(); // Calling sample function
                  }
            }

      }



      function Validate() {

            // Sample function content

      }


</script>


来源:https://stackoverflow.com/questions/5598120/onchange-event-not-firing-in-safari-family-browsersfor-a-fieldset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!