使用 jQuery 从隐藏字段中获取值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3091374/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get value from hidden field using jQuery
提问by X10nD
I have a <input type="hidden" value="" id='h_v' class='h_v'>
Using jQuery I want to alert the user to this value .
我有一个<input type="hidden" value="" id='h_v' class='h_v'>
Using jQuery 我想提醒用户注意这个值。
I am using
我在用
var hv = $('#h_v).text();
alert('x');
But its not working, any clues!
但它不起作用,任何线索!
回答by Sarfraz
回答by dzida
This should work:
这应该有效:
var hv = $('#h_v').val();
alert(hv);
回答by MERT DO?AN
If you don't want to assign identifier to the hidden field; you can use name or class with selector like:
如果您不想为隐藏字段分配标识符;您可以将名称或类与选择器一起使用,例如:
$('input[name=hiddenfieldname]').val();
or with assigned class:
或指定班级:
$('input.hiddenfieldclass').val();
回答by MERT DO?AN
回答by Zeeshan Ali
var hiddenFieldID = "input[id$=" + hiddenField + "]";
var requiredVal= $(hiddenFieldID).val();
回答by Cris
var x = $('#h_v').val();
alert(x);
回答by Coronier
Closing the quotes in
var hv = $('#h_v).text();
would help I guess
关闭引号
var hv = $('#h_v).text();
会帮助我猜