How can I clear the input text after clicking

后端 未结 14 1729
遥遥无期
遥遥无期 2021-01-31 07:26

Using jQuery, how can I clear the input text after I made a click? By default, the value remains in the input field.

For example, I have an input text and the value is <

相关标签:
14条回答
  • 2021-01-31 07:57

    function submitForm()
    {
        if (testSubmit())
        {
            document.forms["myForm"].submit(); //first submit
            document.forms["myForm"].reset(); //and then reset the form values
        }
    } </script> <body>
    <form method="get" name="myForm">
    
        First Name: <input type="text" name="input1"/>
        <br/>
        Last Name: <input type="text" name="input2"/>
        <br/>
        <input type="button" value="Submit" onclick="submitForm()"/>
    </form>
    

    0 讨论(0)
  • 2021-01-31 07:57

    If you need placeholder like behavior. you can use this.

    $("selector").data("DefaultText", SetYourDefaultTextHere);
    // You can also define the DefaultText as attribute and access that using attr() function
    
    $("selector").focus(function(){
    if($(this).val() == $(this).data("DefaultText"))
       $(this).val('');
    });
    
    0 讨论(0)
提交回复
热议问题