<asp:Repeater runat="server" ID="rpt">
<ItemTemplate>
<asp:LinkButton ID="MyLink" runat="server" Text="Fair" ></asp:LinkButton>
<span class="literal">
(<asp:Literal runat="server" ID="Lit1" ClientIDMode="Static" Text='<%# Eval("Value") %>'></asp:Literal>)
</span>
</ItemTemplate>
如上所示,我在Repeater中有一个文字和Link按钮。我想在链接按钮上获取Literal的值。
我已使用给定代码查找链接按钮单击:
$('#MyLink').click(function () {
alert($(this).attr('MyLink'));
});
由于Link按钮位于Repeater内部,因此失败。任何人都可以根据我的要求更新代码。感谢。
答案 0 :(得分:0)
服务器控件在javascript中使用不同的Id。尝试:
$(document).ready(function(){
$('#<%= MyLink.ClientID %>').click(function () {
alert($(this).attr('MyLink'));
});
});
答案 1 :(得分:0)
向您的class
添加link
,
<asp:LinkButton ID="MyLink" class="MyLink" runat="server" Text="Fair" ></asp:LinkButton>
<强> Jquery的强>
$(function(){// write your code in document ready
$('.MyLink').click(function () {
alert($(this).attr('Text'));
});
});
已更新,如果您想获取literal text
,请在class literal
添加literal element
,
(<asp:Literal runat="server" ID="Lit1" ClientIDMode="Static" class='literal' Text='<%# Eval("Value") %>'></asp:Literal>)
并改变jquery code
之类的,
$(function(){// write your code in document ready
$('.MyLink').click(function () {
alert($(this).next('.literal').attr('Text'));
});
});
在查看HTML
,
$(function(){
$('.clsMyLink') .click(function(e){
e.preventDefault();
alert($(this).next('.literal').text());
});
});