How to clear a textbox using javascript

前端 未结 15 2144
失恋的感觉
失恋的感觉 2020-12-05 09:45

I have a


I need a javascript method to clear the value of the textbox when the focus is

相关标签:
15条回答
  • 2020-12-05 10:06

    Give this in input tag of textbox:

    onClick="(this.value='')" 
    
    0 讨论(0)
  • 2020-12-05 10:07

    Use the onfocus and onblur events like this:

    <input type="text" name="yourName" value="A new value" onfocus="if (this.value == 'A new value') this.value = '';" onblur="if (this.value == '') this.value = 'A new value';">
    
    0 讨论(0)
  • 2020-12-05 10:07

    Onfous And onblur Text box with javascript

       <input type="text" value="A new value" onfocus="if(this.value=='A new value') this.value='';" onblur="if(this.value=='') this.value='A new value';"/>
    
    0 讨论(0)
  • 2020-12-05 10:08

    Simple one

    onfocus="javascript:this.value=''" onblur="javascript: if(this.value==''){this.value='Search...';}"
    
    0 讨论(0)
  • 2020-12-05 10:16

    If using jQuery is acceptable:

    jQuery("#myTextBox").focus( function(){ 
        $(this).val(""); 
    } );
    
    0 讨论(0)
  • 2020-12-05 10:18

    just get element using

       function name()
       {  
       document.getElementById('elementid').value = "";
       }
    

    you can call this function on onfocus event of textbox and clear the value

    0 讨论(0)
提交回复
热议问题