[英]Updating input value attribute with jQuery
I currently calculate a random value with jQuery and save it to a variable. 我目前使用jQuery计算随机值,并将其保存到变量中。
I want this variable to be the value of: 我希望此变量的值为:
<input type="text" class="mastery_num" name="mastery_num" id="mastery_num" value="VALUE_FROM_JQUERY"></input>
How can I do this? 我怎样才能做到这一点?
$("#mastery_num").val(your_saved_variable);
.val()
is jQuery's equivalent of the plain JavaScript .value
property. .val()
与普通的JavaScript .value
属性的jQuery等效。 .val()
either returns or sets the value depending on whether you supply a value to it. .val()
返回或设置值,具体取决于您是否为其提供值。
Plain JavaScript version, for future viewers: 纯JavaScript版本,供以后的观看者使用:
document.getElementById("mastery_num").value = your_saved_variable;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.