Let Placeholder dry up in IE, placeholderie up

Source: Internet
Author: User

Let Placeholder dry up in IE, placeholderie up

There are a lot of articles on the Internet to solve the compatibility problem in this aspect, many tricks, learn this trick, let you easily solve the compatibility of Placeholder, let me good people, take it away, thank you ....

The placeholder attribute is added for input in HTML5. A placeholder is provided on input to display the hint of the expected value of the input field in text format. This field is displayed when the input is empty.

For example

<Input type = "text" id = "Title" class = "so-input-d w270" placeholder = "Enter the Title"/>

Like placeholder, but IE6 7 8 9 does not support it. It is blank! At this moment, the mood must be a dog !!!!!, For web development, compatibility must be considered and the industry needs to be conscientious ....

Before use:

After use:

The curative effect is not average.

Current browser support:

Browser IE6/24/60/9 IE10 + Firefox Chrome Safari
Supported? NO YES YES YES YES

 

 

Below is a Js file code, which roughly solves the problem:

(Function ($) {$. fn. myPlaceholder = function (options) {var defaults = {pColor: "# acacac", pFont: "16px", posL: 8, zIndex: "99"}, opts = $. extend (true, defaults, options); if ("placeholder" in document. createElement ("input") return; return this. each (function () {// condition (this).parent().css ("position", "relative"); var isIE = $. browser. msie, version = $. browser. version; // do not support the placeholder browser var $ this = $ (this), msg = $ this. attr ("placeholder"), iH = $ this. outerHeight (), iW = $ this. outerWidth (), iX = $ this. offset (). left, iY = $ this. offset (). top, oInput = $ ("<label>", {"text": msg, "css": {"position": "absolute", "left ": iX + "px", "top": iY + "px", "width": iW-opts. posL + "px", "padding-left": opts. posL + "px", "height": iH + "px", "line-height": iH + "px", "color": opts. pColor, "font-size": opts. pFont, "z-index": opts. zIndex, "cursor": "text "}}). insertBefore ($ this); // content in the initial state var value = $ this. val (); if (value. length> 0) {oInput. hide () ;}; var myEvent; if (isIE & version <9) {myEvent = "propertychange" ;}else {myEvent = "input" ;}$ this. bind (myEvent, function () {var value = $ (this ). val (); if (value. length> 0) {oInput. hide ();} else {oInput. show () ;}}); oInput. click (function () {$ this. trigger ("focus") ;}) ;}} (jQuery );

This solution is implemented using JQUERY plug-ins!

On the page or Js file for operations, use the following method:

$ (Function (){
$ ("# Title"). myPlaceholder ();
});

The Placeholder compatibility problem is solved (ensure that the ID is consistent when the article is marked red )!

Hurry up and get dry!

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.