的ListItem
類沒有onclick
財產。
看起來ListItem
實現了IAttributesAccessor
接口,並且還有一個Attributes
集合。這被記錄爲:
獲取ListItem的屬性名稱和值對的集合,不直接支持該類。
以這種方式放置在標記上的屬性在呈現控件時呈現。這些細節因控制而不同。我嘗試用包含以下的頁面:
<asp:DropDownList ID="_ddl1" runat="server" >
<asp:ListItem Text="Item 1" Value="Item1" onClick="foox();" oncluck="bar(this);" />
</asp:DropDownList>
<asp:ListBox ID="_listBox1" runat="server">
<asp:ListItem Text="Item 1" Value="Item1" onClick="foox();" oncluck="bar(this);" />
</asp:ListBox>
<asp:RadioButtonList ID="_radioList1" runat="server">
<asp:ListItem Text="Item 1" Value="Item1" onClick="foox();" oncluck="bar(this);" />
</asp:RadioButtonList>
在DropDownList
和ListBox
的情況下,這兩個屬性的<Option>
元件上呈現。在RadioButtonList
的情況下,onclick
屬性呈現在<input type="radio">
元素上,但無法識別的oncluck
元素呈現在封閉的<span>
元素上。
請注意,顯然,oncluck
事件永遠不會被解僱。
;-)
嗯...所以我不應該使用它們?我已經測試過它,它可以工作,但如果我將來遇到意想不到的結果,我不想惹它。我喜歡和ASP.NET一起工作,並且我剛剛開始使用Javascript,它確實很有趣,但由於某種原因,它們似乎並沒有像他們應該做的那麼好。 – 2009-04-25 16:36:02
我應該在我上面的評論中增加一個免責聲明:我完全知道我自己缺乏經驗可能是問題所在。 – 2009-04-25 16:40:04
約翰桑德斯用更權威的答案總結了它。如果它適合你,它會適用於你,但我不會推薦做一些實際上沒有支持的東西。 – TheTXI 2009-04-25 16:48:56