jQuery选择器无法从隐藏字段中读取 [英] jquery selector can't read from hidden field

查看:55
本文介绍了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]

但是,将输入设置为隐藏"会阻止选择器工作.有任何线索吗?

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>

控制台显示:

[]

[]

推荐答案

不确定为什么会失败.我定期在工作中执行相同的操作,无论是否隐藏表单域,它都可以正常工作.

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天全站免登陆