开发者

jQuery select value not set

开发者 https://www.devze.com 2023-03-15 21:42 出处:网络
I am trying to set an action for when a select value is between 0 and 2, but with the function below, I am getting the action triggering when the value is not defined. What is the best method for doin

I am trying to set an action for when a select value is between 0 and 2, but with the function below, I am getting the action triggering when the value is not defined. What is the best method for doing so?

$('#html_s开发者_开发问答elect').click(function(){   
    var option = $(this).val();   
    if(option < 3 && option != null){  
    //Do something
   } 
});


What you are doing is perfectly fine.

It is usually better to use the onchange method:

$('#html_select').change(function(){   
    var option = this.value; //DOM's value   
    if(option < 3 && option != null){  
    //Do something
   } 
});

Fiddle: http://jsfiddle.net/maniator/pFFAH/

0

精彩评论

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