![](/img/trans.png)
[英]Uncaught TypeError: Cannot set property 'innerHTML' of null- when setting the innerhtml to a string from an array
[英]Uncaught TypeError: Cannot set property 'innerHTML' of null when setting innerhtml for hiddenfield
我正在嘗試使用引導單選按鈕設置隱藏字段的值。 我有一個 onCLick evnet,當它被點擊時,需要更改 hiddenfield 的值。 這是按鈕和隱藏字段。
<div class="myRow">
<div class="smallCol">
<div class="myRow">
<div class="smallCol title">
<asp:Label ID="lblNewRFID" runat="server" Text="RFID etiketcode"></asp:Label>
</div>
</div>
<div class="myRow">
<div class="smallCol">
<div class="btn-group hiddenRFIDValue" data-toggle="buttons">
<label class="btn btn-default">
<input type="radio" class="btn" name="options" onclick="getHiddenRFIDValue('Always')" id="alwaysRFID" value="Always" autocomplete="off">
Always
</label>
<label class="btn btn-default">
<input type="radio" class="btn" name="options" onclick="getHiddenRFIDValue('Never')" id="neverRFID" value="Never" autocomplete="off">
Never
</label>
<label class="btn btn-default">
<input type="radio" class="btn" name="options" onclick="getHiddenRFIDValue('Sometimes')" id="sometimesRFID" value="Sometimes" autocomplete="off">
Sometimes
</label>
</div>
</div>
</div>
</div>
<asp:HiddenField ID="hiddenRFIDValue" runat="server" />
這是腳本。
<script type="text/javascript">
onclick = function getHiddenRFIDValue(stringValue) {
document.getElementById('hiddenRFIDValue').innerHTML = stringValue;
}
</script>
你們中有人知道為什么我收到錯誤嗎?
您必須刪除“onclick”變量,僅
function getHiddenRFIDValue(stringValue) {
document.getElementById('hiddenRFIDValue').innerHTML = stringValue;
}
和
<asp:HiddenField ID="hiddenRFIDValue" runat="server" />
嘗試更換
<input type="hidden" ID="hiddenRFIDValue" runat="server" />
我用這個修好了。
<script>
$(".hiddenRFIDValue .btn").click(function () {
$("#MainContent_hiddenRFIDValue").val($(this).text());
});
</script>
生成 HTML 時,它更改了隱藏字段的 id
它工作正常如果你只是從函數中省略 onclick
function getHiddenRFIDValue(stringValue) {
document.getElementById('hiddenRFIDValue').innerHTML = stringValue;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.