if(Window.jquery | |window. Zepto) {/** * Set Input box prompt information * @param options * @author rubekid*/ varSetinputtipvalue = Window.setinputtipvalue =function(target, options) {Options= Options | |{}; var_self = Target.get (0); if(_self._inittip) {return false; } target.show (); varcolor = options.color| | " #999999 "; varInputprompt =Target.clone (); varName = target.attr ("name"); varTipText = Options.tiptext | | Target.attr ("Data-tip") | | ""; Inputprompt.val (TipText); Inputprompt.attr ("Type", "text"); Inputprompt.removeattr ("id"); Inputprompt.removeattr ("Name"); Inputprompt.removeattr ("MaxLength"); Inputprompt.removeattr ("Data-tip"); Inputprompt.attr ("Class", Target.attr ("Class")); Inputprompt.attr ("ReadOnly",true); Inputprompt.css ({"Color": color}); _self._inittip=true;//set the label to prevent duplicate binding var_event = "Focus"; if(' Ontouchstart 'inchwindow) {//Mobile Browser Focus does not eject keyboard processingInputprompt.attr ("Disabled", "disabled"); _event= "Touchstart"; } varinit =function(){ if($.trim (Target.val ()) = = "") {Target.val (""); Target.after (inputprompt); Target.hide (); Inputprompt.show (); Inputprompt.bind (_event,function() {setTimeout (function() {target.focus (); }); }); } }; Target.bind ({blur:function() {init (); }, Focus:function() {Inputprompt.detach (); $( This). Show (); }, _reset:function(){ if($.trim (Target.val ()) = = "") {init (); } Else{target.show (); if(inputprompt) {inputprompt.hide (); Inputprompt.remove (); } } } }); Init (); }; /** * JQuery Custom plugin*/ (function ($) { ' Use strict '; /** * Set INPUT gray hint value * @author rubekid*/$.fn.setinputtip=function(options) {return This. each (function(){ varSettings = $.extend ({}, options| |{}); Setinputtipvalue ($ ( This), settings); }); }; }) (Window.jquery||window. Zepto);}
Page Invoke Demo:
<inputtype= "text"Data-tip= "Please enter a query to name"ID= "keyword"name= "keyword" /><Scripttype= "Text/javascript">$(function(){ $("#keyword"). Setinputtip ();}); </Script>
Effect:
jquery Custom Component--input box set default prompt text