我想更新表中的所有selectboxes與另一個選擇框中的值。例如,如果外部選擇框的值爲格林威治媒體,並且用戶單擊該按鈕,則表格中的所有選擇框都應該選擇格林威治媒體。如果表格內的選擇框中沒有Greenwhich媒體,則應添加新選項並進行選擇。添加選擇選項,如果未找到並將其選爲+ jquery
<select class="acc" id="accList" style="width:148px">
<option value="000000000000000001">Greenwich Media</option>
<option value="000000000000000002">Greenwich Media1</option>
</select>
<input id="assignAccounts" class="btn assignAccounts" type="submit" value="Assign this account to All Rows">
<table>
<tr>
<td>
<select class="accSelectandlookup" id="someList0" style="width:148px">
<option value="000000000000000001">Greenwich Media</option>
</select>
</td>
</tr>
<tr>
<td>
<select class="accSelectandlookup" id="someList1" style="width:148px">
<option value="000000000000000002">Greenwich Media1</option>
</select>
</td>
</tr>
</table>
$('.assignAccounts').click(function() {
$('.accSelectandlookup').each(function (i, obj) {
// How do i assign add new option if it does not exist and keep it selected,
// if exists then keep that selected
}
});