zoukankan      html  css  js  c++  java
  • JavaScript实现文本框和密码框placeholder效果(兼容ie8)

    文本框:

    方法一:

    <input type="text" id="add-usbkey-authentication-modal-name" class="form-control"
    value="长度为3-128的数字和字母" name="addUsbkeyAuthenticationModalName"
    onfocus="if(value=='长度为3-128的数字和字母') {value=''}" 
    onblur="if (value=='') {value='长度为3-128的数字和字母'}"
    />

    方法二: 

    <input type="text" name="hotGoods" id="search">
            $(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);
                    }
                });
            }

    密码框:

    <input type="text" value="长度为12-16的数字和字母" id="add-chap-modal-password-show"  class="form-control"/>
    <input type="password" id="add-chap-modal-password" style="display: none" name="addChapModalPassword" class="form-control"/>
            $('#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();
                }
            });
  • 相关阅读:
    python定制类详解
    python格式化
    python3和2的区别
    深度优先和广度优先遍历
    python偏函数
    python匿名函数
    android 应用能够安装在什么地方
    C语言文件操作函数
    病毒木马查杀实战第026篇:“白加黑”恶意程序研究(上)
    函数指针
  • 原文地址:https://www.cnblogs.com/samve/p/13904672.html
Copyright © 2011-2022 走看看