在我的项目中,我在基于数据库值加载页面时创建动态控件。现在我需要为 asp:label
添加点击事件在jquery
所以我尝试了这样的。
ASP.NET
xShowVersion.Style(HtmlTextWriterStyle.Top) = xTop & "px"
xShowVersion.Style.Add(HtmlTextWriterStyle.Height, "40px")
xShowVersion.Style.Add(HtmlTextWriterStyle.Width, "480px")
xShowVersion.Style.Add(HtmlTextWriterStyle.Position, "absolute")
xShowVersion.Style.Add(HtmlTextWriterStyle.Left, "20px")
Dim xlblShow As New Label
xlblShow.Attributes("class") = "downlnkdetails"
xlblShow.Text = "<h2>Show Older Versions<h2>"
xShowVersion.Controls.Add(xlblShow)
DivLeftVersion.Controls.Add(xShowVersion)
JS
<script language="javascript" type="text/javascript">
$(document).ready(function() {
BindButtonClickEvent();
});
function BindButtonClickEvent() {
$('#<%= xlblShow.ClientID %>').click(function() {
alert('Hai');
return false;
});
}
</script>
但是它显示错误。如何为asp标签或任何其他控件编写事件jquery
?
正在使用Asp.Net 2008
最佳答案
对于动态添加的内容,您需要使用下面的代码片段
$(document).on('click', '#ID' , function(e){
alert('clicked');
});
关于javascript - 为动态创建的asp控件添加Jquery事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35458074/