jquery选择器无法从隐藏字段中读取

前端之家收集整理的这篇文章主要介绍了jquery选择器无法从隐藏字段中读取前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
( answers aggregated into another question)

以下jquery 1.3.2代码工作:

  1. <input type="select" value="236434" id="ixd" name='ixd' />
  2.  
  3. <script>
  4. console.log( $('#ixd') );
  5. console.log( $("input[name='ixd']") );
  6. </script>

控制台显示

[input#ixd 236434]

[input#ixd 236434]

但是将输入设置为“隐藏”可防止选择器工作.任何线索?

  1. <input type="hidden" value="236434" id="ixd" name='ixd' />
  2.  
  3. <script>
  4. console.log( $('#ixd') );
  5. console.log( $("input[name='ixd']") );
  6. </script>

控制台显示

[]

[]

解决方法

不知道为什么会失败.我定期在工作上做同样的事情,无论是否隐藏表单域,它都可以工作.

也许尝试这样:

  1. <input type="hidden" value="236434" id="ixd" name='ixd' />
  2.  
  3. <script>
  4. console.log($("#xid").val())
  5. </script>

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

猜你在找的jQuery相关文章