jquery function on dropdown select

前端 未结 7 2283
臣服心动
臣服心动 2020-12-14 08:36

I need to run a jquery function if a certain dropdown option is selected.


                        
    
提交评论

  • 2020-12-14 09:14
        $(document).ready(function() {
          $("select[name='dropdown']").change(function() {
             if($(this).val()==2){
                 //do what u want here
               }//u can check your desired value here
         });
       });
    

    I think you want this.

    0 讨论(0)
  • 2020-12-14 09:16

    Try this demo http://jsfiddle.net/JGp9e/

    This will help, have a nice one!

    code

    $('select[name="dropdown"]').change(function(){
    
        if ($(this).val() == "2"){
            alert("call the do something function on option 2");
         }        
    });​
    

    HTML

    <select name="dropdown" size=1>
        <option value="1">option 1</option>
        <option value="2">option 2</option>
    </select>​
    
    0 讨论(0)
  • 2020-12-14 09:16

    use

    $("#idofselectbox").change(function(){
    // your code here
    });
    

    hope this helps....

    0 讨论(0)
  • 2020-12-14 09:20
    $(document).ready(function() {
      $("select[name='dropdown']").change(function() {
         alert($(this).val());
      });
    });
    
    0 讨论(0)
  • 2020-12-14 09:20

    You need to use change function

    $('select[name=dropdown]').change(function() {
        alert($(this).val());
    });
    
    0 讨论(0)
  • 提交回复
    热议问题