jquery选择器不能从隐藏字段读取 [英] jquery selector can't read from hidden field

查看:169
本文介绍了jquery选择器不能从隐藏字段读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

聚集到另一个问题的答案

以下jquery 1.3.2代码工作原理:

The following jquery 1.3.2 code works:

<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#ixd 236434]

[input#ixd 236434]


$ b b

但是,将输入设置为hidden会阻止选择器工作。任何线索?

However setting the input to "hidden" prevents the selectors working. Any clues?

<input type="hidden" value="236434" id="ixd" name='ixd' />

<script>
console.log( $('#ixd') );
console.log( $("input[name='ixd']") );
</script>

控制台显示:


[]

[]

[]


推荐答案

不知道为什么会失败。我在工作中定期做同样的事情,它的工作,无论formfield被隐藏或不。

Not sure why that would be failing. I do the same thing at work on a regular basis, and it works regardless of the formfield being hidden or not.

也许尝试一下:

<input type="hidden" value="236434" id="ixd" name='ixd' />

<script>
    console.log($("#xid").val())
</script>

这将得到隐藏字段的值。要从表单字段获取值,需要使用 .val()方法。

That will get you the value of the hidden field. To get the value out of a form field, the .val() method needs to be used.

这篇关于jquery选择器不能从隐藏字段读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆