How can I clear the input text after clicking

后端 未结 14 1727
遥遥无期
遥遥无期 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:30

    try this

    $("input[name=search-mini]").on("search", function() {
     //do something for search
    });
    
    0 讨论(0)
  • 2021-01-31 07:30
        enter code here<form id="form">
    <input type="text"><input type="text"><input type="text">
    
    <input type="button" id="new">
    </form>
    <form id="form1">
    <input type="text"><input type="text"><input type="text">
    
    <input type="button" id="new1">
    </form>
    <script type="text/javascript">
    $(document).ready(function(e) {
        $("#new").click( function(){
            //alert("fegf");
        $("#form input").val('');
        });
    
          $("#new1").click( function(){
            //alert("fegf");
        $("#form1 input").val('');
        });
    });
    </script>
    
    0 讨论(0)
  • 2021-01-31 07:33

      $('.mybtn').on('click',
          function(){
              $('#myinput').attr('value', '');
          }
      );
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    
      <button class="mybtn">CLEAR</button>
      <input type="text" id="myinput" name="myinput" value="ааааааааа">

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

    Using jQuery ...

    $('#submitButtonsId').click(
        function(){
            $(#myTextInput).val('');
        });
    

    Using pure Javascript ...

    var btn = document.getElementById('submitButton');
    btn.onclick = function(){ document.getElementById('myTextInput').value="" };
    
    0 讨论(0)
  • 2021-01-31 07:37

    I am supposing you are trying to create a effect, where the textbox contains a label. And when the user click in the textbox, it disappears and lets the user input the text. You do not require Jquery for this.

    <input type="text" value="Input Text" onfocus="this.value=''" onblur="(this.value=='')? this.value='Input Text':this.value;" />
    

    Demo

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

    I would recommend to use this since I have the same issue which got fixed.

    $('input:text').focus(
        function(){
            $(this).val('');
        });
    
    0 讨论(0)
提交回复
热议问题