[Dry] compatible with HTML5 placeholder Properties-Update version v0.10102013

Source: Internet
Author: User

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

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.