JQuery placeholder plugin allows IE to also support placeholder properties
Case: whole search box, need default placeholder for "Please enter keyword", get focus, placeholder disappears or unavailable (does not affect normal input), after losing focus, if the user has no content input, placeholder continues to appear, continue to occupy. This code I think the front end has been very easy to write it, now HTML5 original has this "placeholder" attribute, the effect is the same as the above case description (each supported browser may not be consistent within the performance, but the role is consistent), So how does this attribute gracefully downgrade to support all modern browsers? The answer or script is JavaScript.
;(function($) {$.fn.extend ({placeholder:function () { if("Placeholder"inchDocument.createelement ("Input")) { return This //If native supports the placeholder property, the object itself is returned}Else { return This. each (function () { var_this = $ ( This); _this.val (_this.attr ("placeholder")). Focus (function () { if(_this.val () = = = _this.attr ("placeholder") {_this.val ("")}). blur (function () { if(_this.val (). length = = 0) {_this.val (_this.attr ("Placeholder"))}})}) (jQuery);
script to determine whether the browser natively supports the placeholder property to dynamically load this script
if in document.createelement ("input")) { $.getscript ("jquery.placeholder.js",function () { $ ("#keyword"). placeholder (); let Id=keyword elements support placeholder, switch to your own selector })}
JQuery placeholder plugin allows IE to also support placeholder properties