How to set the 'selected option' of a select dropdown list with jquery

后端 未结 6 1499
南笙
南笙 2021-01-31 09:07

I have the following jquery function:

$.post(\'GetSalesRepfromCustomer\', {
    data: selectedObj.value
}, function (result) {
    alert(result[0]);
    $(\'sele         


        
6条回答
  •  无人及你
    2021-01-31 09:32

    Try this :

    $('select[name^="salesrep"] option[value="Bruce Jones"]').attr("selected","selected");
    

    Just replace option[value="Bruce Jones"] by option[value=result[0]]

    And before selecting a new option, you might want to "unselect" the previous :

    $('select[name^="salesrep"] option:selected').attr("selected",null);
    

    You may want to read this too : jQuery get specific option tag text

    Edit: Using jQuery Mobile, this link may provide a good solution : jquery mobile - set select/option values

提交回复
热议问题