Placeholder's IE compatibility issues

Source: Internet
Author: User

The following JS file is referenced in HTML and is written in the style file: Input,textarea{color: #999;} Input:focus,textarea:focus{color: #333;}
I am simply using the global style to write this, if you do not want all input boxes are prompted, you can give the required input specific classes, such as:. txt{color: #999;} . Txt:focus{color: #333;}
(function ($) {
/** * Spoofs placeholders in browsers this don ' t support them (eg Firefox 3) * * Copyright (Dan Bentley) * License D under the Apache License 2.0 * * Author:dan Bentley [Github.com/danbentley] */
Return If native support is available. if ("Placeholder" in document.createelement ("input")) return;
$ (document). Ready (function () {$ (': Input[placeholder] '). \ (':p assword '). each (function () {Setupplaceholder ($ ()  )); });
$ (':p Assword[placeholder] '). each (function () {Setuppasswords ($ (this));      });  $ (' form '). Submit (function (e) {Clearplaceholdersbeforesubmit ($ (this)); }); });
function Setupplaceholder (input) {
var placeholdertext = input.attr (' placeholder ');
Setplaceholderorflagchanged (input, placeholdertext);   Input.focus (function (e) {if (Input.data (' changed ') = = = True) return;  if (input.val () = = = Placeholdertext) input.val (");  }). blur (function (e) {if (input.val () = = =) Input.val (placeholdertext);  }). Change (function (e) {input.data (' changed ', Input.val ()!== '); }); }
function setplaceholderorflagchanged (input, text) {(Input.val () = = = ")? Input.val (text): Input.data (' changed ', true); }
function Setuppasswords (input) {var passwordplaceholder = Createpasswordplaceholder (input); Input.after (Passwordplaceholder);
(Input.val () = = = ")? Input.hide (): Passwordplaceholder.hide ();
$ (input). blur (function (e) {if (Input.val ()!== ") return;   Input.hide ();  Passwordplaceholder.show ();     });   $ (Passwordplaceholder). focus (function (e) {input.show (). focus ();  Passwordplaceholder.hide (); }); }
function Createpasswordplaceholder (input) {return $ (' <input> '). attr ({placeholder:input.attr (' placeholder '), Value:input.attr (' placeholder '), id:input.attr (' id '), readonly:true}). addclass (input.attr (' class ')); }
function Clearplaceholdersbeforesubmit (form) {Form.find (': Input[placeholder] '). each (function () {if ($ (). Data ('   Changed ') = = = True) return;  if ($ (this). val () = = = $ (this). attr (' placeholder ')) $ (this). Val ('); }); }}) (JQuery);

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Placeholder's IE compatibility issues

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.