在我的HTML表單中(如在大多數HTML表單中),標籤與字段共享相同的ID。我試圖返回到標籤標籤的HTML一旦點擊與匹配的ID複選框。jQuery給出輸入ID,獲取標籤文本
<input id="yes1" type="checkbox">
<label for="yes1">This is the text it should return.</label>
而且我的jQuery:
$('input').change(function() {
if (this.checked) {
var response = $('label#' + $(this).attr('id')).html();
}
}
但很可惜,反應出來爲NULL。
你仰視'標籤#yes1',但沒有對象相匹配的選擇。 – jfriend00