( answers aggregated into another question )
以下 jquery 1.3.2 代码有效:
<input type="select" value="236434" id="ixd" name='ixd' />
<script>
console.log( $('#ixd') );
console.log( $("input[name='ixd']") );
</script>
控制台显示:
[input#ixd 236434]
[input#ixd 236434]
但是,将输入设置为“隐藏”会阻止选择器工作。有什么线索吗?
<input type="hidden" value="236434" id="ixd" name='ixd' />
<script>
console.log( $('#ixd') );
console.log( $("input[name='ixd']") );
</script>
控制台显示:
[]
[]
最佳答案
不知道为什么会失败。我在工作中经常做同样的事情,无论表单域是否隐藏,它都有效。
也许试试这个:
<input type="hidden" value="236434" id="ixd" name='ixd' />
<script>
console.log($("#xid").val())
</script>
这将为您提供隐藏字段的值。要从表单字段中获取值,需要使用 .val()
方法。
关于jquery选择器无法从隐藏字段读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/996644/