• input表单文本内容鼠标点击消失,鼠标移走恢复


    第一种,最简单的办法

    就是直接在input表单里加上 onfocus="this.value=''" onblur="this.value=''"即<input type="text" value="1111" onfocus="this.value=''" onblur="this.value='1111'"/>

    第二种,用jquery实现:(网上找的例子)

    js:

    代码
    $(function() {
    //取出有clear类的input域
    //
    (注: "clear once" 是两个class clear 和 once)
    $('#testform input.clear').each(function(){
    //使用data方法存储数据
        $(this).data( "txt", $.trim($(this).val()) );
    })
    .focus(
    function(){
    // 获得焦点时判断域内的值是否和默认值相同,如果相同则清空
        if ( $.trim($(this).val()) === $(this).data("txt") ) {
        $(
    this).val("");
      }
    })
    .blur(
    function(){
    // 为有class clear的域添加blur时间来恢复默认值
    //
     但如果class是once则忽略
        if ( $.trim($(this).val()) === "" && !$(this).hasClass("once") ) {
    //Restore saved data
        $(this).val( $(this).data("txt") );
        }
      });
    });

    Dom:

    <input type="text" class="clear" value="Always cleared" />
    <input type="text" class="clear once" value="Cleared only once" />
    <input type="text" value="Normal text" />
  • 相关阅读:
    【9408】数的计数
    【rlz03】十六进制转十进制
    【rlz02】二进制转十进制
    【rlz01】完全数
    【a101】高精度实数加法
    【9406】2的幂次方
    【42.86%】【Codeforces Round #380D】Sea Battle
    【26.83%】【Codeforces Round #380C】Road to Cinema
    【9932】饥饿的牛
    【9933】单词的划分
  • 原文地址:https://www.cnblogs.com/lch880/p/1684222.html
Copyright © 2020-2023  润新知