How to get select box option value in jQuery

后端 未结 8 1674
逝去的感伤
逝去的感伤 2021-02-03 10:47

How to get the value of option select box in jQuery if I have the code like this,


                        
    
提交评论

  • 2021-02-03 11:41

    Use class instead of id like this..

    <select class='media' name='media'>
        <option value='1'>media1</option>
        <option value='2'>media2</option>
        <option value='3'>media3</option>
    </select>
    
    $(document).ready(function(){
        $(".media").live("change",function(){
            var id = $(this).val();
            var dataString = 'id='+ id;
            alert(id); return false;
        }); 
    }); 
    
    0 讨论(0)
  • 提交回复
    热议问题