你的小提琴,但它的作品:Click here
您的問題與您的js - 更改:
$(".clone_dept").live("change", function() { //<-- not really sure why live isn't working
if ($(this).val() == 'Dept #1') {$(".clone_attendees").val(dept_1);}
if ($(this).val() == 'Dept #2') {$(".clone_attendees").val(dept_1);}
if ($(this).val() == 'Dept #3') {$(".clone_attendees").val(dept_1);}
if ($(this).val() == 'Dept #4') {$(".clone_attendees").val(dept_1);}
if ($(this).val() == 'Dept #5') {$(".clone_attendees").val(dept_1);}
}).change(); // trigger once if needed
}); // <-- This shouldnt be here
到:
$(".clone_dept").change(function() {
if ($(this).val() == 'Dept #1') {$(".clone_attendees").val(dept_1);}
if ($(this).val() == 'Dept #2') {$(".clone_attendees").val(dept_2);}
if ($(this).val() == 'Dept #3') {$(".clone_attendees").val(dept_3);}
if ($(this).val() == 'Dept #4') {$(".clone_attendees").val(dept_4);}
if ($(this).val() == 'Dept #5') {$(".clone_attendees").val(dept_5);}
}).change(); // trigger once if needed
雖然這並不能真正解決如何選擇最接近的輸入。在你的小提琴的情況下,它是使用該類的唯一元素。如果此行結構將被複制並重用,請使用此選項來選擇正確的輸入。
if($(this).val() == 'Dept #1') {$(this).parent().next("td").children(".clone_attendees").val(dept_1);}
編輯: 更好的是,使用一個數組指派權值,而不是具有5行,如果statments。
var dept = ["Person #1, Person #2, Person #3, Person #4, Person #5","Person #6, Person #7, Person #8, Person #9, Person #10","Finance Persons","IT Persons","Marketing Persons"];
將值添加到的選項標籤
<option value=0>Dept #1</option>
然後
$(".clone_dept").change(function() {
if($(this).val() == 'Dept #1') {
$(this).parent()
.next("td")
.children(".clone_attendees")
.val(dept[$(this).val()])
}
}).change(); // trigger once if needed
'最接近()'指*始祖匹配*元件。 – alex
「最接近」是什麼意思?請向我們展示您的HTML。 – SLaks
請在您的回答中包含html標記 – Andre