"JavaScript" allows IE8 to use placeholder

Source: Internet
Author: User

    var placeholder=function ($element) {var $ = window.jquery;        var version = parsefloat ($.browser.version);        var isIE8 = $.browser.msie && version < 9; var text = $element. attr ("Cm-placeholder") | |        $element. attr ("placeholder");            if (isIE8) {var $placeholderContainer = $element. Closest ("Div");            $placeholderContainer. css ({"position": "relative"}); Window.settimeout (function () {var getfakeplaceholder = function () {var cmplaceholder                    Id = $element. attr ("Cm-placeholder-id");                    var $fakePlaceholder; if (Cmplaceholderid && cmplaceholderid.length > 0) {$fakePlaceholder = $placeholderCont                        Ainer.find ("#" + Cmplaceholderid);                        if ($fakePlaceholder && $fakePlaceholder. length > 0) {return $fakePlaceholder;       }                    }             var cm_placeholder_id = _.uniqueid ("cm-placeholder-");                    var fakeplaceholder = ' <span id= ' + cm_placeholder_id + ' "class=" Cm-placeholder "> ' + text + ' </span> ';                    $fakePlaceholder = $ (fakeplaceholder);                    $placeholderContainer. Append ($fakePlaceholder);                        $fakePlaceholder. On ("click", Function (e) {e.stoppropagation ();                    $element. focus ();                    });                    $element. On (' Focus ', function () {$fakePlaceholder. Hide ();                    }). On (' Blur ', function () {showfakeplaceholderifnotext ();                    });                    $element. attr ("Cm-placeholder-id", cm_placeholder_id);                return $fakePlaceholder;                };                var $fakePlaceholder = Getfakeplaceholder ();                var showfakeplaceholderifnotext = function () {    if ($element. val () = = = ") {var EP = $element. Position (); var top = Ep.top;                        -Wp.top; var left = Ep.left;                        -Wp.left;                        var height = $element. Height ()-2;                            $fakePlaceholder. css ({' top ': Top + ' px ', ' left ': Left + ' px ',                        "Height": Height + "px", "line-height": Height + "px"                        });                    $fakePlaceholder. Show ();                    } else {$fakePlaceholder. Hide ();                }                };            Showfakeplaceholderifnotext ();        }, 0); } else {$element. attr ("placeholder", text | |        ""); }    }

  

"JavaScript" allows IE8 to use placeholder

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.