简体   繁体   English

jQuery在内容页面的服务器控件上不起作用

[英]jquery not working on server controls in content page

i am having a TextBox txt on a content page. 我在内容页面上有一个TextBox txt。 when i try this 当我尝试这个

$(function(){
$("#txt").focus(function(){alert("abcd"); });
});

it doesn't work. 它不起作用。 It's working if i am using it on simple .aspx page with no master page. 如果我在没有母版页的简单.aspx页上使用它,则可以正常工作。

如果"#txt"<asp:textbox />控件,则在呈现页面时它将获得客户端ID,要选择asp.net控件,您需要执行$("[id*='txt']")

View the HTML source. 查看HTML源。 I think the most likely problem is the renaming of the controls by prepending the content section's id. 我认为最可能的问题是通过在内容部分的ID前面添加控件来重命名。 You can change this with the ClientIDMode property: 您可以使用ClientIDMode属性更改此设置:

<asp:TextBox ID="txt" runat="server" ClientIDMode="static"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM