placeholder(兼容IE)

$j(function() {

    supportPlaceholder = 'placeholder' in document.createElement('input'),

        placeholder = function (input) {

            var text = input.attr('placeholder'),
                defaultValue = input.defaultValue;

            if (!defaultValue) {

                input.val(text).addClass("phcolor");
            }

            input.focus(function () {

                if (input.val() == text) {

                    $j(this).val("");
                }
            });


            input.blur(function () {

                if (input.val() == "") {

                    $j(this).val(text).addClass("phcolor");
                }
            });


            input.keydown(function () {

                $j(this).removeClass("phcolor");
            });
        };


    if (!supportPlaceholder) {

        $j('input').each(function () {

            text = $j(this).attr("placeholder");

            if ($j(this).attr("type") == "text") {

                placeholder($j(this));
            }
        });
    }
});

  

原文地址:https://www.cnblogs.com/xueyu-1/p/5586620.html