javascript - 如果输入了数据,请清空文本框

标签 javascript jquery html css

如果按下取消按钮,弹出文本框中输入的数据将被清除。

我使用下面的代码来执行此操作,

function clear()
{
 document.getElementById("spacevalidate").setTextValue() = "";
}

html是针对弹出框的

<div id="overlay_form" style="display:none">
       <h2> Create New Incident Type</h2>
        <br />
        Name
        <input type="text" id="spacevalidate" style="height:30px;" name="title" maxlength="30" /><br />
        <div style="width:180px;float:right;margin:20px 5px 0 10px">
            <button id="bsave" type="submit" name="save" title="Save" class="forward">Save</button>
            <button style="margin-right:10px;" type="button" id="close" name="cancel" class="forward backicon">Cancel</button>
        </div>

更新:

$(document).ready(function(){
        //open popup
        $("#addalist").click(function(){
            $("#overlay_form").fadeIn(1000);
            positionPopup();
        });

1.现在我输入一些数据并按下取消按钮,我再次打开相同的弹出窗口,数据在文本框中可用。如果输入了一些数据并按下取消按钮,我想在每次打开时清除它。

最佳答案

试试这个,

function clear()
{
   document.getElementById("spacevalidate").value = "";
}

关于javascript - 如果输入了数据,请清空文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16565599/

相关文章:

javascript - 如何让页面之间的屏幕恢复为黑色?

javascript - 使用文本区域显示多行文本

php - 如何使用 html 表单数据创建 fpdf 表单

javascript - Canvas 弧线绘制奇怪的形状 - CoffeeScript

javascript - jQuery(window).load(function() 中断脚本

javascript - 如何消除鼠标悬停时的不良影响

javascript - 使用 AJAX POST 请求存储数字数据

javascript - Kendo 的 Angular 指令 : "kendo" is undefined?

html - Div 2 Column Set Set using images and block-links inline-block 不起作用 - Shopify/liquid

javascript - CSS/JavaScript 将 DIV 滑出并滑入