jQuery prevent change for select

前端 未结 13 1373
無奈伤痛
無奈伤痛 2020-11-28 10:51

I want to prevent a select box from being changed if a certain condition applies. Doing this doesn\'t seem to work:

$(\'#my_select\').bind(\'change\', funct         


        
13条回答
  •  被撕碎了的回忆
    2020-11-28 11:31

    Try this:

    http://jsfiddle.net/qk2Pc/

    var my_condition = true;
    var lastSel = $("#my_select option:selected");
    
    $("#my_select").change(function(){
      if(my_condition)
      {
        lastSel.prop("selected", true);
      }
    });
    
    $("#my_select").click(function(){
        lastSel = $("#my_select option:selected");
    });
    

提交回复
热议问题