example, using JS lost focus and gain focus method
JS Code
The code is as follows |
Copy Code |
<input type= "text" name= "s" value= "hint text" onfocus= "if (value = = ' Hint text ') {value = '} ' onblur= ' if (value = = ') {value= ' Prompt text '} '/> |
How to implement in WordPress
The code is as follows |
Copy Code |
<input type= "text" name= "s" id= "S" size= "15″value=" <?php Echo (Get_search_query) ? Get_search_query (): ' Your Default Text ');?> "onfocus=" if (this.value = ' Your Default Text ') {this.value = ';} ' onblur= ' if (this.value = ") {this.value = ' <?php _e (' Your Default Text ', ' Jessica ')?> ';} ' Name= "S" id= "s"/> |
jquery Code
The code is as follows |
Copy Code |
$ (document). Ready (function () { Search box $ (' #keyword '). focus (function () { if ($ (this). val () = ' Please enter keywords! ') { $ (this). Val (""); } }); $ (' #keyword '). blur (function () { if ($ (this). val () = "") { $ (this). Val (' Please enter keywords! '); } }); }); |
An instance of a Web site
code is as follows |
copy code |
$ (function () { $ ("[placeholder]"). focus (function () { var input = $) ); if (input.val () = = Input.attr ("placeholder")) { Input.val (""); Input.removeclass ("placeholder"); } }). blur (function () { var input = $ (this); if (input.val () = "" | | Input.val () = = Input.attr ("placeholder")) { Input.addclass ("placeholder"); Input.val (Input.attr (" Placeholder ")); } }). blur (); $ ("[placeholder]"). Parents ("form"). Submit (function () { $ (this). Find ("[placeholder]"). each (function () { var input = $ (this); Input.val (input.val () = = Input.attr ("placeholder")? "": Goog.string.htmlEscape (Input.val ()); }) ); }); |