可以說我有id爲paremeter和兩個選擇框jQuery的追加到(通過ID動態)
<select id="one" onchange="Fill(2)"></select>
<select id="two" onchange="Fill(3)"></select>
<select id="three"></select>
我的功能
function Fill(id){
//some manupulation
$('<option/>').val(substr[0]).html(substr[1]).appendTo('#two');
}
但而不是做很多功能
if(id==2) {$('<option/>').val(substr[0]).html(substr[1]).appendTo('#two');}
if(id==3) {$('<option/>').val(substr[0]).html(substr[1]).appendTo('#three');}
我想要類似
$('<option/>').val(substr[0]).html(substr[1]).appendTo(DYNAMIC);
我不完全確定,因此評論,但它看起來像你只是想將新的'選項'追加到當前更改的元素?所以...不會'$('').val(/*..*/)。html(/*..*/)。appendTo($(this));'work? –