JavaScript实现文本框和密码框placeholder效果(兼容ie8)
发布日期:2021-05-07 01:01:18 浏览次数:23 分类:精选文章

本文共 1308 字,大约阅读时间需要 4 分钟。

文本框:

方法一:

方法二: 

$(document).ready(function () {            $("#search").val('请输入您要搜索的内容').css('color', '#ccc');            replacePlaceholder($("#search"));        });        function replacePlaceholder(input) {            var originalvalue = input.val(); //请输入您要搜索的内容            // console.log(originalvalue);            input.focus(function () {                if ($.trim(input.val()) == originalvalue) {                    input.css('color', '#333');                    input.val('');                }            });            input.blur(function () {                if ($.trim(input.val()) == '') {                    input.css('color', '#ccc');                    input.val(originalvalue);                }            });        }

密码框:

$('#add-chap-modal-password-show').focus(function () {            var text_value = $(this).val();            if (text_value == this.defaultValue) {                $('#add-chap-modal-password-show').hide();                $('#add-chap-modal-password').show().focus();            }        });                $('#add-chap-modal-password').blur(function () {            var text_value = $(this).val();            if (text_value == "") {                $('#add-chap-modal-password-show').show();                $('#add-chap-modal-password').hide();            }        });

 

上一篇:[GXOI/GZOI2019]宝牌一大堆
下一篇:[CTSC2006]歌唱王国

发表评论

最新留言

能坚持,总会有不一样的收获!
[***.219.124.196]2025年04月13日 03时13分03秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章