我有一個下拉菜單,其中包含使用php從數據庫填充的選項。我爲每個選項創建了一個顯示按鈕,以在下拉菜單中顯示。每個按鈕都會調用移除選項功能並傳遞其值。我試圖從下拉列表中刪除選項,當其中一個按鈕被點擊。此時,我的功能在單擊按鈕時不起任何作用。從選擇中刪除選項使用javascript
<select id="myselect" name="myselect">
<option value='161'>Option 1</option>
<option value='162'>Option 2</option>
<option value='163'>Option 3</option>
<option value='164'>Option 4</option>
</select>
<button type='button' class='btn btn-primary btn-xs' onClick="removeOption('161')">Option 1<span class='glyphicon glyphicon-remove' aria-hidden='true'></span></button>
<button type='button' class='btn btn-primary btn-xs' onClick="removeOption('162')">Option 2<span class='glyphicon glyphicon-remove' aria-hidden='true'></span></button>
<button type='button' class='btn btn-primary btn-xs' onClick="removeOption('163')">Option 3<span class='glyphicon glyphicon-remove' aria-hidden='true'></span></button>
<button type='button' class='btn btn-primary btn-xs' onClick="removeOption('164')">Option 4<span class='glyphicon glyphicon-remove' aria-hidden='true'></span></button>
function removeOption(option) {
var optionValue = "'[value=" + "\"" + option + "\"" + "]'";
$(this).find(optionValue).remove();
$("#myselect").selectpicker("refresh");
}
檢查的'this' – Andreas