的document.getElementById('身份证')值在ASP.net javascript函数失败 [英] document.getElementById('id').value failing in ASP.net javascript function
问题描述
隐藏字段:
<input type="hidden" id="hidOrg1" runat="server" value="" />
<input type="hidden" id="hidBT" runat="server" value="" />
JavaScript函数:
javascript function:
function doGetWave(obj) {
//debugger
var brk = document.getElementById('hidBT').value;
//var brkId = document.getElementById('hidBI').value;
var org = document.getElementById('hidOrg1').value;
session = obj.options[obj.selectedIndex].value;
sWaveText = obj.options[obj.selectedIndex].text;
if (brk == "") {
window.location.href = "url.aspx?multiple=" + org + "&wave=" + sWaveText + "&strORGId=multiple";
}
else {
window.location.href = "url.aspx?multiple=" + org + "&wave=" + sWaveText + "&BRKType=" + brk + "&strORGId=multiple";
}
}
codebehind:
codebehind:
protected void Page_Load(object sender, EventArgs e)
{
hidOrg1.Value = strOrgId;
hidBT.Value = "";
}
与预期的对象的VAR BRK = ...我想不出它是怎么了JavaScript函数的错误了。拉我的头发! (
The javascript function errors out with "Object Expected" at the var brk = ... and I cannot figure out where it is going wrong. Pulling my hair out! :(
推荐答案
当你把 =服务器
在标准的HTML标签,ASP.Net轧液的ID以确保它独特的(就像它有自己的控制一样)。您需要使用ASP.Net分配ID访问的元素。试试这个:
When you place runat="server"
in an standard HTML tag, ASP.Net mangles the ID to ensure that it's unique (just like it does with its own controls). You need to access the element using the ID that ASP.Net assigned. Try this:
var brk = document.getElementById('<%= hidBT.ClientID %>').value;
var org = document.getElementById('<%= hidOrg1.ClientID %>').value;
其他信息
如果您使用的是4.0框架,可以在元素,页面或应用程序级别更改此行为。查看<一个href=\"http://beyondrelational.com/blogs/hima/archive/2010/07/16/all-about-client-id-mode-in-asp-net-4.aspx\">this链接一个体面的小教程。如果您选择设置的ClientIDMode
到
静态,你可以访问您最初分配的ID的元素(它们不会改变)。
If you're using the 4.0 framework, you can change this behavior at the element, page, or application level. Check out this link for a decent little tutorial. If you choose to set the ClientIdMode
to Static
, you can access your elements by the ID's that you originally assigned (they will not be changed).
这篇关于的document.getElementById('身份证')值在ASP.net javascript函数失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!