[英]Get value of hidden input field in JS
I need to get the value of a hidden input field using JS,我需要使用 JS 获取隐藏输入字段的值,
var credoff = parseInt($(this).children('input.credoff:hidden').val());
which works fine in FF but does not work in IE, the input im talking of is the following...在 FF 中工作正常但在 IE 中不起作用,我所说的输入如下......
<input type='hidden' value='$row->coff' class='credoff' name='credoff'/>
Could you try input[type='hidden']
?你可以试试input[type='hidden']
吗?
Are there many other elements with the 'credoff' class? 'credoff' class 还有很多其他元素吗?
There are comments in the jQuery documentation for the:hidden selector related to this. jQuery 文档中有与此相关的:hidden 选择器的注释。
http://api.jquery.com/hidden-selector/ http://api.jquery.com/hidden-selector/
Apparently in IE, the:hidden selector also selects elements, so it's possible that you're not getting back the right element.显然在 IE 中,:hidden 选择器也会选择元素,因此您可能无法取回正确的元素。 You could try你可以试试
var credoff = parseInt($(this).children('input.credoff:hidden').not('option').val());
This might work:这可能有效:
var credoff = parseInt($(this).children('input[name="credoff"]').val());
Although I don't know what 'this' is.虽然我不知道“这个”是什么。 More code would be helpful.更多代码会有所帮助。
Or this:或这个:
var credoff = parseInt($(':input[type:"hidden"][name:"credoff"]').val());
This must work:这必须有效:
var credoff = parseInt($(this).children('input[name="credoff"][type="hidden"]').val()); var credoff = parseInt($(this).children('input[name="credoff"][type="hidden"]').val());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.