我有下一个 C# 代码(有效):
// Write data into the checkboxes
RepeaterVocabularyWords.DataSource = new[] { correctWord1, correctWord2, incorrectWord1, incorrectWord2 };
RepeaterVocabularyWords.DataBind();
// Get data from the checkboxes
protected void ButtonAccept_Click(object sender, EventArgs e)
{
foreach (RepeaterItem item in RepeaterVocabularyWords.Items)
{
if (item.ItemType == ListItemType.Item
|| item.ItemType == ListItemType.AlternatingItem)
{
CheckBox CheckBoxVocabularyWord = (CheckBox)item.FindControl("CheckBoxVocabularyWord");
if (CheckBoxVocabularyWord.Checked)
{
}
}
}
下一个带有 JQuery 代码的 ASP(有效):
$(document).ready(function () {
$("input[id$='ButtonAccept']").click(function (e) {
if ($('span.storeCheck input:checked').length != 2) {
alert("You have to choose only the 2 words that means the same!");
e.preventDefault();
}
然后,如果我写“span class="storeCheck"..”行,上面的转发器代码可以工作,但上面的 c# 代码不行:
<asp:Repeater ID="RepeaterVocabularyWords" runat="server" OnItemCommand="Repeater1_ItemCommand">
<ItemTemplate>
<<span class="storeCheck"><input runat="server" type="checkbox" ID="CheckBoxVocabularyWord" title="<%# Container.DataItem %>" /></span>
</ItemTemplate>
</asp:Repeater>
相反,如果我写“asp:CheckBox ID="..”,上面的 c# 代码可以工作,但 jQuery 的东西不行。
<asp:Repeater ID="RepeaterVocabularyWords" runat="server" OnItemCommand="Repeater1_ItemCommand">
<ItemTemplate>
<asp:CheckBox ID="CheckBoxVocabularyWord" runat="server" Text="<%# Container.DataItem %>" />
</ItemTemplate>
</asp:Repeater>
我怎样才能使两者都起作用?