使用jQuery从隐藏字段中获取价值
问题描述:
我有一个<input type="hidden" value="" id='h_v' class='h_v'>
使用jQuery,我想提醒用户该值.
I have a <input type="hidden" value="" id='h_v' class='h_v'>
Using jQuery I want to alert the user to this value .
我正在使用
var hv = $('#h_v).text();
alert('x');
但是它不起作用,有任何线索!
But its not working, any clues!
答
改为使用 val()
的text()
var hv = $('#h_v').val();
alert(hv);
您遇到了以下问题:
- 单引号未关闭
- 您在输入字段中使用
text()
- 您回显的是
x
而不是变量hv
- Single quotes was not closed
- You were using
text()
for an input field - You were echoing
x
rather than variablehv