开发者

select onchange firing twice in ie7

开发者 https://www.devze.com 2023-03-01 10:37 出处:网络
this is really wierd, not sure why this is happening but my onchange is firing twice. any help/idea开发者_Python百科s is greatly appreciated...

this is really wierd, not sure why this is happening but my onchange is firing twice. any help/idea开发者_Python百科s is greatly appreciated...

<select id="ddlGender" onchange="myfunc()">
  <option value="1">-select-</option>
  <option value="2">Male</option>
  <option value="3">Female</option>
  <option value="4">NotSpecified</option>
</select>


Your java script code should be in java script file loaded in your head:

$(document).ready(function(){

  $("#ddlGender").unbind('click').change(myfunc);

  var myfunc = function (e)
  {
    // Do something important....
  }
});

If I remember correctly you need to unbind click event from select in IE in order to avoid firing event twice.

And your html should not have onchange any more:

<select id="ddlGender">
  <option value="1">-select-</option>
  <option value="2">Male</option>
  <option value="3">Female</option>
  <option value="4">NotSpecified</option>
</select>
0

精彩评论

暂无评论...
验证码 换一张
取 消