使用Javascript函数设置输入值

我目前正在使用YUI小工具。我也有一个Javascript函数来验证divYUI为我绘制的输出:


Event.on("addGadgetUrl", "click", function(){

    var url = Dom.get("gadget_url").value;  /* line x ------>*/

    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为""?


GCT1015
浏览 653回答 3
3回答

肥皂起泡泡

试试...为YUIDom.get("gadget_url").set("value","");正常 Javascriptdocument.getElementById('gadget_url').value = '';与JQuery$("#gadget_url").val("");

慕容708150

MVC5中的以下作品:document.getElementById('theID').value = 'new value';

HUX布斯

根据用例的不同,您使用的是javascript(element.value = x)还是jQuery$(element).val(x);jQuery 何时x为undefined空字符串,而javascript "undefined"为字符串。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript