使用Javascript函数设置输入值 [英] Set Value of Input Using Javascript Function
本文介绍了使用Javascript函数设置输入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在使用YUI小工具。我也有一个Javascript函数来验证来自YUI为我绘制的 div
的输出:
I'm currently using a YUI gadget. I also do have a Javascript function to validate the output that comes from the div
that YUI draws for me:
Event.on("addGadgetUrl", "click", function(){
/* line x ------>*/ var url = Dom.get("gadget_url").value;
if (url == "") {
error.innerHTML = "<p> error" /></p>";
} else {
/* line y ---> */
/* I need to add some code in here to set the value of "gadget_url" by "" */
}
}, null, true);
这是我的 div
:
<div>
<p>URL</p>
<input type="text" name="gadget_url" id="gadget_url" style="width: 350px;" class="input"/>
<input type="button" id="addGadgetUrl" value="add gadget"/>
<br>
<span id="error"></span>
</div>
您可以看到我的问题是,如何设置 gadget_url $的值c $ c>要
?
As you can see my question is, how can I set the value of gadget_url
to be ""
?
推荐答案
试试.. 。
for YUI
Try... for YUI
Dom.get("gadget_url").set("value","");
正常 Javascript
document.getElementById('gadget_url').value = '';
使用JQuery
$("#gadget_url").val("");
这篇关于使用Javascript函数设置输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文