如何獲取匹配元素的引用? '這'是不正確的。jQuery:每個如何引用匹配的對象
例如在這裏我試圖警告與元素值。
//how do i get this to reference the object it matches.
$("#txtFirstName,#txtLastName,#txtDOB").each(
function() { alert(this.val()); }
);
如何獲取匹配元素的引用? '這'是不正確的。jQuery:每個如何引用匹配的對象
例如在這裏我試圖警告與元素值。
//how do i get this to reference the object it matches.
$("#txtFirstName,#txtLastName,#txtDOB").each(
function() { alert(this.val()); }
);
嘗試:
$("#txtFirstName,#txtLastName,#txtDOB").each(
function() { alert($(this).val()); }
);
這是this
,而是利用val()
你需要一個jQuery對象。
$(this).val();
在這種情況下,this
是對實際DOM元素的引用。您需要將其包裝到jQuery對象中才能使用val()
函數。
$(this).val()