HTML5 has made many enhancements to the Web Form, such as input type, Form validation, and so on. Placeholder is another property added by HTML5, and when input or textarea is set, the content of the value is displayed as a gray hint in the text box, and the hint text disappears when the text box gets the focus.
The placeholder compatibility method is provided here, which is updated as follows:
1. Modify the method to the inherited object of the node native object
2. Compatible with text boxes with input type password
3. Provide the style name as a parameter, you can set the style flexibly, fix a problem of style setting
4. Resolved Event monitoring compatibility issues
5. jquery Plugin version available
Here is a snippet of jquery, a detailed description, an online demo:
http://levi.cg.am/?p=3171
? 1. [Code] Take a look at the calling method first:
A specific text object
$ (' #tmp '). PlaceHolder (' abc ');
Set all text objects
$ (' input '). PlaceHolder (' abc ');
Call method once and for all
$ (' [placeholder] '). PlaceHolder (' abc ');
2. [The code]js method is as follows:
;(function ($) {
$.fn. PlaceHolder = function (className) {
var _set = function ($em, opt) {
For (i in opt) {
switch (i) {
Case ' value ': $em. Val (Opt[i]); Break
Case ' class ':
if (opt[i].length) {
$em. Toggleclass (Opt[i]);
}
Break
Default: $em. attr (i, opt[i]);
}
}
};
if (' Placeholder ' in $ (' <input/> ') [0]) {
return this;
}
Return This.each (function () {
var $this = $ (this),
init = {
' Type ': $this. attr (' type '),
' Placeholder ': $this. attr (' placeholder ')
};http://www.huiyi8.com/huawen/?
$this. Bind ({pattern
' Init ': function () {
_set ($ (this), {
' Type ': Init.type,
' Class ': ClassName? ClassName: ",
' Value ': '
});
},
' OPTs ': function () {
_set ($ (this), {
' Type ': ' Text ',
' Class ': ClassName? ClassName: ",
' Value ': Init.placeholder
});
},
' Focus ': function () {
var $this = $ (this);
if ($this. val () = = Init.placeholder) {
$this. Trigger (' init ');
}
},
' Blur ': function () {
var $this = $ (this);
if ($this. val () = = ") {
$this. Trigger (' opts ');
}
}
});
if (Init.placeholder && $this [0].value! = undefined) {
$this. Trigger (' blur ');
}
});
};
}) (JQuery);
?
[Dry] compatible with HTML5 placeholder Properties-Update version v0.10102013