简体   繁体   English

Javascript无法在ASP.NET中找到隐藏的字段?

[英]Javascript cannot find hidden Field in ASP.NET?

I am trying save the disabled property value of a hidden field to track the disabled state of a button between postbacks, with the following javascript 我正在尝试使用以下JavaScript保存隐藏字段的Disabled属性值,以跟踪回发之间按钮的禁用状态。

function TrackState(buttonID)
{
   var trackingField = document.getElementById("_tracking" + buttonID);

    return false; // prevent default action
}

HTML HTML

<input type="hidden" name="_trackingButton1" value="true" />

but trackingField seems to be null each time, what is going wrong here 但是trackingField每次似乎都为空,这是怎么回事

You need to assign the id property of your element (not just name) and it should work like this: 您需要分配元素的id属性(不仅是name),它应该像这样工作:

<input type="hidden" id="_trackingButton1" name="_trackingButton1" value="true" />

I hope this helps. 我希望这有帮助。

In your function 在你的职能

function TrackState(buttonID) { } 函数TrackState(buttonID){}

what is the buttonID value exactly. buttonID的值到底是多少? I hope it is "Button1". 我希望它是“ Button1”。 And as the function says getElementById the input has the property id with the same value. 正如函数所说的getElementById,输入具有相同值的属性id。

getElementById()方法专门查找id值:

<input type="hidden" id="_trackingButton1" name="_trackingButton1" value="true" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM