Compatible with placeholder and placeholder

Source: Internet
Author: User

Compatible with placeholder and placeholder

As we all know, IE9 is not compatible with the placeholder attribute, so we have customized a jQuery plug-in, placeHolder. js. The code for placeHolder. js is as follows:

/*** This control is compatible with IE9 or lower, and is specially designed for the * Author: quranjie * Date: */$ (function () that does not support the placeholder attribute below IE9 () {// if placeholder is not supported, use jQuery to complete if (! Issuppplacplaceholder () {// traverses all input objects, except for the password box $ ('input '). not ("input [type = 'Password']"). each (function () {var self = $ (this); var val = self. attr ("placeholder"); input (self, val) ;});/* Special Handling of the password box * 1. create a text box * 2. switch between getting focus and losing focus */$ ('input [type = "password"] '). each (function () {var pwdField = $ (this); var pwdVal = pwdField. attr ('placeholder'); var pwdId = pwdField. attr ('id'); // rename the input id to the original id followed by 1pwdField. after ('<input id = "' + pwdId + '1" type = "text" value = '+ pwdVal + 'autocomplete = "off"/> '); var pwdPlaceholder =$ ('#' + pwdId + '1'); pwdPlaceholder. show (); pwdField. hide (); pwdPlaceholder. focus (function () {pwdPlaceholder. hide (); pwdField. show (); pwdField. focus () ;}); pwdField. blur (function () {if (pwdField. val () = '') {pwdPlaceholder. show (); pwdField. hide () ;}}) ;}}); // determines whether the browser supports the placeholder attribute function issuppplacplaceholder () {var input = document. createElement ('input'); return 'placeholder' in input;} // jQuery replaces the processing function input (obj, val) {var $ input = obj; var val = val; $ input. attr ({value: val}); $ input. focus (function () {if ($ input. val () = val) {$ (this ). attr ({value :""});}}). blur (function () {if ($ input. val () = "") {$ (this ). attr ({value: val });}});}

Call method:

<Html> This code is compatible with IE9 and earlier versions. jQuery selects a stable version of 1.7.2. The code implementation takes into account multiple password input boxes on a page.


I want to create some part-time projects after work to earn some extra money. The main projects are Android, IOS, PHP, and website construction. These projects are especially good at Android, PHP, and website construction.

If you are interested, please send me a private email! If You Are the One, thank you!


Is there any plug-in that allows ie6 ie7 ie8 to support the placeholder attribute in input?

Placeholder is HTML5.
Cannot be used in IE6-8. You can use JQ to set this parameter.
Input a value. value = "" When JQ determines the focal point "";
If the input is empty when the focus is removed, add "Please input"

An example is as follows:
$ (Document ). ready (function () {$ ("input "). focusin (function () {if ($ (this ). val () = "enter") {$ (this ). val ("") ;}}); $ ("input "). focusout (function () {if ($ (this ). val () = "") {$ (this ). val ("enter ");}});});

What is placeholder?

Found for you
A variable represents the new window.
Let's take an example.
<Html>
<Script langruage = "javascript">
Var placeHolder = folder holder open('holder.html ', 'placeholder', 'width = 200, height = 200 ');

</Script>
</Html>
Save your program as a. html file. When you click open, a new window is displayed. The new window can be controlled by placeHolder in the program. Next, let's look at this:
<Html>
<Script langruage = "javascript">
Var placeHolder = folder holder open('holder.html ', 'placeholder', 'width = 200, height = 200 ');
PlaceHolder. close ();
</Script>
</Html>
Added a sentence: placeHolder. close (); run a new program. The pop-up window will be closed immediately after it is opened. Do you know this?

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.