我做了一个组合框。
我从数据库获取数据并将名字的值设置为选定的组合框,但它不起作用。这是我的代码:
$('#invoices_invoicesbundle_invoicestype_firstname').val('{{firstname}}');
这是我的选择框 html:
<select id="invoices_invoicesbundle_invoicestype_firstname" required="required" name="invoices_invoicesbundle_invoicestype[firstname]">
<option selected="selected" disabled="disabled">Please Choose</option>
<option value="2">Ilyas</option>
<option value="3">Arif</option>
<option value="4">Ali</option>
<option value="5">Arslan</option>
</select>
{{firstname}}
值为 Ali,如何将 Ali 设置为选中?
最佳答案
您需要通过“值”而不是文本节点来选择选项。看看这个,如果有帮助请告诉我:http://jsfiddle.net/4jGZD/
$('#invoices_invoicesbundle_invoicestype_firstname').val(4);
关于javascript - 如何更改组合框的选定值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19245216/