jquery Custom Component--input box set default prompt text

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.