javascript - 如何使用javascript/jquery获取隐藏字段的值

标签 javascript jquery html

我必须嵌入下面的代码片段才能获取隐藏字段 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”的元素似乎没有在htmljs处设置value属性?

<input type="hidden" id="customerDeviceIdReferenceCode" name="customerDeviceIdReferenceCode"/>

关于javascript - 如何使用javascript/jquery获取隐藏字段的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32175865/

相关文章:

javascript - 如何使用 js 或 jquery div.width css 属性?

javascript - 将 js 转换为 php 以获得背景色 cookie

html - 如何增加单选按钮中文本的大小,它应该居中对齐

javascript - ReactJS:如何在 &lt;footer/> 内填充?

html - 摆脱子菜单中的底部边框

javascript - 如何使用 Chart.js 在圆环图的中心添加文本?

javascript - jquery - 添加监听器到生成的 html

jQuery .fadeIn 同时发生

javascript - redux中组件渲染机制是如何工作的

Jquery 正则表达式 : substitute <br/>