从jQuery中的asp.net runat服务器获取ID [英] Getting ID from asp.net runat server in jQuery
本文介绍了从jQuery中的asp.net runat服务器获取ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用ASP.NET在jQuery中制作一些东西。但是来自 runat =server
的ID与HTML中使用的ID不同。
I'm trying make some stuff in jQuery using ASP.NET. But the ID from runat="server"
is not the same as the id used in HTML.
我用过使用它从这种情况下获取ID:
I used to use this to get the ID from this situation:
$("#<%=txtTest.ClientID%>").val();
但在这种情况下,它不起作用。我对此无能为力。
But in this case, it does not work. I'm clueless as to why.
Javascript
Javascript
/* Modal */
function contatoModal() {
//alert("Test");
alert($("#<%=txtTest.ClientID%>").val());
}
HTML
< input runat="server" id="txtTest" value="test" />
任何提示?
推荐答案
<%= txtTest.ClientID%>
应该可以工作,但不能在服务器端脚本不执行的单独javascript文件中工作。另一种可能性是使用类选择器:
<%= txtTest.ClientID %>
should work but not in a separate javascript file where server side scripts do not execute. Another possibility is to use a class selector:
<input runat="server" id="txtTest" value="test" class="txtTest" />
然后:
var value = $('.txtTest').val();
这篇关于从jQuery中的asp.net runat服务器获取ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文