我必须在下面的片段中嵌入以获取隐藏字段customerDeviceIdReferenceCode的值。
<body>
<form id="form1" runat="server">
<div>
<input type="hidden" id="customerDeviceIdReferenceCode" name="customerDeviceIdReferenceCode"/>
</div>
</form>
<script type="text/javascript">
//<#-- populate customer device id -->
var io_bbout_element_id = 'customerDeviceIdReferenceCode';
//<#-- do not install Flash -->
var io_install_flash = false;
//<#-- do not install Active X -->
var io_install_stm = false;
//<#-- do not run Active X -->
var io_exclude_stm = 12;
//<#-- enable detection of real IP -->
var io_enable_rip = true;
(function () {
var asyncSnareScript = function() {
var element = document.createElement('script');
element.src = "https://ci-mpsnare.iovation.com/snare.js";
document.body.appendChild(element);
//function(){
// var current_value = $('#customerDeviceIdReferenceCode').val();
// alert(current_value);
//}
};
if (window.addEventListener) {
window.addEventListener('load', asyncSnareScript, false);
} else if (window.attachEvent) {
window.attachEvent('onload', asyncSnareScript);
} else {
//<#-- If all else fails, just append the script immediately. -->
asyncSnareScript();
}
})();
</script>
</body>
但是当我试图获取价值时 var current_value = $(&#39; #customerDeviceIdReferenceCode&#39;)。val(); 它让我空白。 当我查看页面源时,我发现创建了一个新节点。
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="QYw2oyL6KhN1E9tHbNHuW31ZS/2qIXGM4FMkKCTtafh172i2YMgOBy820zB42Z39lDPYEe/dJY4QtfDXAiA98WRBpWwpkqL0Y+aBATbVGb0=" />
</div>
如果我使用, var current_value = $(&#39; #__ VIEWSTATE&#39;)。val(); 我可以得到value.But我想使用id customerDeviceIdReferenceCode获取值。 任何帮助,将不胜感激。 提前谢谢。
答案 0 :(得分:1)
想要使用id customerDeviceIdReferenceCode
获取值
具有id
“customerDeviceIdReferenceCode”的元素似乎没有value
html
设置js
属性?
<input type="hidden" id="customerDeviceIdReferenceCode" name="customerDeviceIdReferenceCode"/>