1
我有一個名爲CustomPickedTable
的Table
,這個Table
具有屬性的行,例如<td Data-question-id="5">Example</td>
,有些行根本沒有任何屬性。只是<td>example</td>.
如果ID缺失用jquery填充另一個隱藏字段中的行
我想要做的是能EM分類到不同的hiddenfields,這些都是我的hiddenfields:
@Html.HiddenFor(model => model.SelectedCustomQuestions, new { @id = "SelectedQuestionsWithAttr" })
@Html.HiddenFor(model => model.SelectedQuestions, new { @id = "SelectedQuestionsWithNoAttr" })
,我現在所擁有的代碼是與屬性"data-question-id"
所有行被填充SelectedQuestionsWithAttr
那是我擁有屬性的行的隱藏字段。
但我想我的jquery代碼也填充沒有屬性的行被填充到我的SelectedQuestiosnWithNoAttr
hiddenfield。
這是剛剛填補SelectedQuestionsWithAttr hiddenfield代碼:
var selectedQuestionsWithAttr = $("#SelectedQuestionsWithAttr");
var currentIds = new Array();
$("#CustomPickedTable").find("td").each(function() {
var clickedId = $(this).attr("data-question-id");
currentIds.push(clickedId);
});
selectedQuestionsWithAttr.val(currentIds.join(","));
$("form").submit();
}
有沒有我可以添加到我的jQuery代碼這方面的任何解決方案?
由於提前
它應該可以只是「如果表td沒有任何屬性做這個」 – Obsivus 2012-03-29 10:47:57
這就是td:not([data-question-id])選擇器是。你在那個函數中做的是由你決定的,但你確實要求將這些行添加到你的SelectedQuestionsWithNoAttr變量中,爲此,它們需要以某種方式被識別。 – CodingIntrigue 2012-03-29 10:58:11