从 jquery 访问内容页面元素
我正在尝试从 jquery 访问文本框和隐藏字段的值。我得到的值是未定义的。
这些控件位于我的母版页的内容页面内。
<input id="datepickerContact" type="text" runat="server" />
<input type="hidden" runat="server" id="IAssignmentId" clientidmode="Static" />
在 javascript 函数中:
var Insid = $("#datepickerContact");
var firstcontactDate = $("#IAssignmentId");
alert(Insid.val());
alert(firstcontactDate.val());
提前感谢
BB
I am trying to access the value of a textbox and Hidden field from jquery. I am getting value as undefined.
These controls are inside the content page of my master page.
<input id="datepickerContact" type="text" runat="server" />
<input type="hidden" runat="server" id="IAssignmentId" clientidmode="Static" />
In the javascript function :
var Insid = $("#datepickerContact");
var firstcontactDate = $("#IAssignmentId");
alert(Insid.val());
alert(firstcontactDate.val());
Thanks in advance
BB
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您还没有提到 ClientIDMode用于
datepickerContact
控件。默认情况下,该模式将是 Predicatable(如果是迁移的站点,则为 AutoID),并且它将使用父命名容器的串联生成 html side id,在内容页面的情况下,该父命名容器将是内容占位符。简而言之,
datepickerContact
文本框将具有类似于“content1_datepickerContact”的 html id 属性,因此 jquery 选择器将找不到 html 控件。简单的解决方案是将 ClientIDMode 用作静态。例如,
另一种方法是传递通过 ClientID 属性到您的 java 脚本函数。如果您的函数是在标记 (aspx) 上定义的,那么您可以使用服务器端指令将客户端 ID 嵌入到脚本中,如 rick schott 所示。如果您的函数位于外部 js 中,那么您必须将客户端 ID 作为参数传递。
You haven't mentioned the ClientIDMode for
datepickerContact
control. By default, the mode would be Predicatable (or AutoID if a migrated site) and it will generate the html side id using concatenation of parent naming container which will be content placeholder in case of content pages.In short,
datepickerContact
textbox will have html id attribute as something similar to "content1_datepickerContact" and hence jquery selector would not find the html control.The simple solution is to use ClientIDMode as static. For example,
Yet another way is to pass the actual client id (irrespective of client id mode) obtained via ClientID property to your java-script function. If your function is defined on the markup (aspx) then you can use server side directive to embed client id in script as illustrated by rick schott. If your function lies in external js then you have to pass the client id as parameter.
您可以通过编写此
var insid=$("#<%= datepickerContact.ClientID %>").val();
来访问
警报(内部);
you can access by writing this
var insid=$("#<%= datepickerContact.ClientID %>").val();
alert(insid);