How to set the first option on a select box using jQuery?

前端 未结 17 918
终归单人心
终归单人心 2020-11-28 03:18

I have two HTML select boxes. I need to reset one select box when I make a selection in another.


    
    
    
    





And the javascript...

$('#name0').change(function(){
    if($('#name0').val() == '') {
        $('select.name').each(function(index){
          $(this).val($(this).data('default'))  
        })
    } else {
      $('select.name').val($('#name0').val() );
    }
});

See http://jsfiddle.net/8hvqN/ for a working version of the above.

提交回复
热议问题