[英]Jquery/Javascript Setting the attribute value of a textfield
I have a 我有一个
<input type='text' id='text' value='' />
How do I programmatically set the value attrribute using JQuery/Javascript 如何使用JQuery / Javascript以编程方式设置attrribute值
简单易行的方法是:
$("#text").val ("foo");
它就像这样简单:
$("#text").attr("value", "some value");
Javascript将是:
document.getElementById('text').value = 'Blahblah';
In jQuery, you'd do it like this: 在jQuery中,你会这样做:
$("#text").val("my new value");
You might also want to read the jQuery documentation on this topic 您可能还想阅读有关此主题的jQuery文档
Without jQuery: 没有jQuery:
document.getElementById("text").setAttribute("value", "my new value");
Hope that helps. 希望有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.