IE-compatible placeholder settings

Source: Internet
Author: User

 

HTML5 placeholder is not supported on IE. Solution

Add directly to the webpage

<! -- Placeholder compatible with IE -->
<SCRIPT src = "static/JS/placeholder. js"> </SCRIPT>

You can.

// JavaScript Document(function($) {    /**     * Spoofs placeholders in browsers that don‘t support them (eg Firefox 3)     *      * Copyright 2011 Dan Bentley     * Licensed 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]‘).not(‘:password‘).each(function() {            setupPlaceholder($(this));        });             $(‘:password[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 ($(this).data(‘changed‘) === true) return;            if ($(this).val() === $(this).attr(‘placeholder‘)) $(this).val(‘‘);        });    }})(jQuery);

 

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.