如何在javascript函数中将文本框id分配到javascript变量中。 [英] How to assign textbox id into javascript variable in javascript function.
本文介绍了如何在javascript函数中将文本框id分配到javascript变量中。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试以两种方式将文本框ID值分配到var autocomplete。
方式I:
< script type =text / javascript>
函数ShowProcessImage12(){
// alert('test');
var autocomplete = document.getElementById('txtitem1');
}
< / script>
方式II:
<脚本类型= 文本/ JavaScript的 >
函数ShowProcessImage12(){
var autocomplete = document.getElementById('<%= txtitem1.ClientID%>');
}
< / script>
aspx页面。
****** **
<表>
< tr>
< td>
< asp:TextBox ID =txtitem1runat =serverstyle =z-index:1000; Width =200Font-Names =Sans-SerifFont-Bold =trueFont-Size =13
< / td>
< / tr>
< / table>
注意:我测试了警报功能,知道它是否调用javascript函数。所以,它调用javascript函数。
但我在自动完成时得到空值。如何将文本框id值分配到自动完成变量。
解决方案
请参阅:
http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientid.aspx [ ^ ],
http: //msdn.microsoft.com/en-us/library/system.web.ui.control.clientidmode.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/1d04y8ss.aspx [ ^ ],
http://weblogs.asp.net/asptest/ archive / 2009/01/06 / asp-net-4-0-clientid-overview.aspx [ ^ ]。
你会找到全面的解释,并清楚地了解你的案例。
-SA
< blockquote>我认为看看以下内容将解决您的问题。
[ ^ ]
:)
只有你问题的解决方案
代码文件nt.getElementById为您提供整个控件对象
,您可以访问该对象的属性ID。
function ShowProcessImage12(){
// alert(& amp; amp;#39; test& amp; amp;#39;);
var element = document .getElementById(' txtitem1' 跨度>);
var autocomplete = element.id;
}
I tried in two way to assing the textbox id value into var autocomplete.
Way I:
<script type="text/javascript"> function ShowProcessImage12() { //alert('test'); var autocomplete = document.getElementById('txtitem1'); } </script>
Way II:
<script type="text/javascript"> function ShowProcessImage12() { var autocomplete = document.getElementById('<%=txtitem1.ClientID%>'); } </script>
aspx page.
********
<table> <tr> <td> <asp:TextBox ID="txtitem1" runat="server" style=" z-index:1000;" Width="200" Font-Names="Sans-Serif" Font-Bold="true" Font-Size="13" </td> </tr> </table>
Note: i tested with alert function to know it invokes javascript function or not. so, it invokes javascript function.
but i am getting null value in autocomplete. how to assign textbox id value into autocomplete variable.
解决方案
Please see:
http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientid.aspx[^],
http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientidmode.aspx[^],
http://msdn.microsoft.com/en-us/library/1d04y8ss.aspx[^],
http://weblogs.asp.net/asptest/archive/2009/01/06/asp-net-4-0-clientid-overview.aspx[^].
You will find comprehensive explanation and will clearly understand what to do in your case.
—SA
I think that Having a look at the following will solve your problem.
[^]
:)
there is solution in your question only
the code document.getElementById gives you the whole control objet
and you can access property ID of that object.
function ShowProcessImage12() { //alert(&amp;#39;test&amp;#39;); var element=document.getElementById('txtitem1'); var autocomplete = element.id; }
这篇关于如何在javascript函数中将文本框id分配到javascript变量中。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文