Javascript text input fields that display instruction (placeholder) text

后端 未结 7 2070
抹茶落季
抹茶落季 2021-02-04 13:17

What\'s the best way to have a text input field that displays instructions of what to enter in that field in gray. When you focus on that input field, the gray instruction text

相关标签:
7条回答
  • 2021-02-04 13:21

    Look at this one: http://fuelyourcoding.com/scripts/infield/

    0 讨论(0)
  • 2021-02-04 13:21
    <input type="text" name="myText" value="Enter Name" style="color:gray" onfocus="this.value=''">
    
    0 讨论(0)
  • 2021-02-04 13:26

    placeholder code - name

    name of the variable is,

    var name=$("#con-name");
    var nameval="Enter your name";
    
    
    
    name.val(nameval);
    name.focus(function(){  
         if (this.value == nameval ) { 
             this.value = ''; 
         }; 
        }).blur(function(){ 
             if (this.value == '') {    
             this.value = nameval;  
        };  
     });
     //submit to clear code
     $("#sub_con_page").click(function() {  
        if(name.val()==nameval) { 
           name.val(""); 
         } 
     });
    

    DEMO LINK

    0 讨论(0)
  • 2021-02-04 13:39

    Make the input transparent and put the text behind it. Check the value onload, onblur to decide if the text should be visible or not. Make it invisible onfocus.

    For example: http://dorward.me.uk/tmp/label-work/example.html (you just need to style the label and input with different foreground colours)

    0 讨论(0)
  • 2021-02-04 13:44

    You can use watermark plugin in jquery.use this link.

    example

     $(this).Watermark("your instructions");
    
    0 讨论(0)
  • 2021-02-04 13:46

    You don't need javascript for this.

    HTML5:

    <input type="text" id="email" name="email" placeholder="Enter your email address">
    

    This works in modern browsers. If you add modernizr.js to your page then it'll work in all browsers.

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