开发者

jQuery .val() method is triggering a change event in IE8

I have a select that has a change event on it, which shows a confirm box. If the user clicks 'cancel', then i change the value back to what it was before (with .val()). However, in IE8 this is triggering a change event again, restarting the cycle.

There must be a cleaner way to set the select back to it's previous value, without triggering another change event, but i can't think of it :/ Any suggestions?开发者_JAVA百科 Here's what i'm doing right now, which may well be rather clumsy:

  $("#quiz_style").change(function(){
    var selected = $(this).val(); 
    if(selected == "classic"){
      if (!confirm("confirmation message for changing to classic")) {
          $(this).val('sequential');
          return false;
      }      
    } else if(selected == "sequential"){
      if (!confirm("confirmation message for changing to sequential")) {
          $(this).val('classic');
          return false;
      }       
    }
  });

EDIT - bit more info. My original post was a bit misleading, as it said that the use of val() triggers another change event. That's not quite true i think: what happens is that the select is changed back, with nothing untoward happening, but then when i click elsewhere on the page (anywhere) the change event is triggered again.


It shouldn't do that, and it doesn't seem to: http://jsbin.com/omewa6 Tested in IE8 (and IE6, and Chrome, and Firefox, and Opera...). You'll want to look elsewhere in your code for the problem, although I can't immediately think what it would be if that code is what you're actually using...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜