Javascript调试问题 [英] Javascript debugging problem
问题描述
在我的aspx文件中,
我试图检索控件值,例如:使用下面的代码:
In my aspx file,
I tried to retrieve the control values, e.g. using the piece of code below:
function onChange_Dept() {
debugger;
var v1 = document.getElementById('<%=TextBoxLastName%>').value;
var v2 = document.getElementById('<%=TextBoxEmail.ClientID%>').value;
}
当我运行调试时,动态代码如下所示
When I run debugging, the dynamic code is show below
function onChange_Dept() {
debugger;
var v1 = document.getElementById('System.Web.UI.WebControls.TextBox').value;
var v2 = document.getElementById('ctl00_ContentPlaceHolder1_TextBoxEmail').value;
}
其中v1为null,v2正确返回值。我不知道为什么在动态代码中,TextBoxLastName没有被正确访问。
where the v1 is null, and v2 returns value correctly. I don't know why in the dynamic code, the TextBoxLastName is not accessed correctly.
The 2 controls in the aspx look like below:
<pre lang="HTML">
<td class="stylecol2" colspan="2">
<asp:TextBox ID="TextBoxLastName" runat="server" class="styleTxtbox" ToolTip="Requester's Last Name"></asp:TextBox>
</td>
...
<td colspan="3" style="height: 29px">
<asp:TextBox ID="TextBoxEmail" runat="server" class="styleTxtbox" ontextchanged="TextBoxEmail_TextChanged" ></asp:TextBox>
<asp:RegularExpressionValidator ID="validateEmail1" runat="server" ControlToValidate="TextBoxEMail" ErrorMessage="Invalid email" ValidationExpression="^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$" ForeColor="#FF3300"></asp:RegularExpressionValidator>
</td>
</pre>
我不知道知道为什么2 c ontrols在动态调试中表现不同。希望你能帮我解决这个问题。谢谢。
我尝试过:
JavaScript中遇到问题调试和未知原因
I don't know why the 2 controls behave differently in dynamic debugging. Wish you can help me for this answer. Thanks.
What I have tried:
Got problem in JavaScript debugging and unknown why
推荐答案
ForeColor = #FF3300 > < / asp:RegularExpressionValidator >
< / td >
< / pre >
" ForeColor="#FF3300"></asp:RegularExpressionValidator> </td> </pre>
我不知道为什么2个控件在动态调试中表现不同。希望你能帮我解决这个问题。谢谢。
我尝试过:
在JavaScript调试中遇到问题并且未知原因
I don't know why the 2 controls behave differently in dynamic debugging. Wish you can help me for this answer. Thanks.
What I have tried:
Got problem in JavaScript debugging and unknown why
您错过了.ClientID更改
You missed out the .ClientID change
var v1 = document.getElementById('<%=TextBoxLastName%>').value;
to
to
var v1 = document.getElementById('<%=TextBoxLastName.ClientID%>').value;
这篇关于Javascript调试问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!