我必须嵌入下面的代码片段才能获取隐藏字段 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 = $('#customerDeviceIdReferenceCode').val(); 它给了我空白。 当我查看页面源代码时,我发现创建了一个新节点。
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="QYw2oyL6KhN1E9tHbNHuW31ZS/2qIXGM4FMkKCTtafh172i2YMgOBy820zB42Z39lDPYEe/dJY4QtfDXAiA98WRBpWwpkqL0Y+aBATbVGb0=" />
</div>
如果我使用, var current_value = $('#__VIEWSTATE').val(); 我可以获得该值。但我想使用 id customerDeviceIdReferenceCode 获取该值。 任何帮助,将不胜感激。 提前致谢。
最佳答案
want to fetch the value using id customerDeviceIdReferenceCode
具有id
“customerDeviceIdReferenceCode”的元素似乎没有在html
、js
处设置value
属性?
<input type="hidden" id="customerDeviceIdReferenceCode" name="customerDeviceIdReferenceCode"/>
关于javascript - 如何使用javascript/jquery获取隐藏字段的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32175865/