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();
                }
            });
  • 相关阅读:
    prometheus client_golang使用
    etcd相关知识
    基于kubernetes v1.17部署dashboard:v2.0-beta8
    浅谈 Linux namespace
    使用kubeadm部署K8S v1.17.0集群
    和我一步步部署 kubernetes 集群
    go语言开发(二)---变量
    Golang学习笔记(一)-Go语言环境安装以及运行代码
    pycharm中设置pylint工具
    keeplive使用
  • 原文地址:https://www.cnblogs.com/samve/p/13904672.html
Copyright © 2011-2022 走看看