我是一個新手與Jquery,我想追加一個選擇選項。這可以工作,當我選擇新添加的選項。我在alert中未定義。追加選擇選項並選擇附加選項警報顯示未定義+ Jquery
var selects = $(this).closest('div').find('.accSelectandlookup') ;
//Check if the accid is already present in the selectoptions and if not then add
if (!selects.find('option[value="' + accid + '"]').length) {
alert(accid); // This throws up the correct value
selects.append('<option value="' + accid + '">Attach to Existing : ' + accname + '</option>');
}
我在做什麼錯?
在此先感謝
selects.change(function(){
alert('selected value is ' + selects.filter(":selected").val()); // This throws undefined
})
創建小提琴請 –
控制檯中的日誌選擇,並確保您正確地得到select元素。 –