Jquery 更改输入值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6041294/
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
Jquery change value on input
提问by Ste
Hi have an hidden input into an display:none div . I need to chenge the value of my input hidden but i can't.. I try this:
您好,在 display:none div 中有一个隐藏的输入。我需要改变我的输入值隐藏但我不能..我试试这个:
<div style='display:none'>
<input id='hidden_input' name='xxx' type='hidden' value='' />
</div>
$("#hidden_input").val('test');
Hey help??
嘿帮忙??
回答by Rory McCrossan
Have you included the jQuery library in your page, and put that line changing the value in the correct place?
您是否在页面中包含了 jQuery 库,并将更改值的那一行放在正确的位置?
Something like this:
像这样的东西:
<script type="text/javascript" src="location/of/jquery.js"></script>
<script type="text/javascript">
$(function() {
$("#hidden_input").val('test');
});
</script>
回答by Yuda Prawira
see this, could help you http://jsfiddle.net/g2fsQ/
看到这个,可以帮助你http://jsfiddle.net/g2fsQ/
回答by Nico Prat
The code you wrote should work. You also may have forgotten this bit of code :
您编写的代码应该可以工作。你也可能忘记了这段代码:
$(document).ready(function(){
// your code here
});