zoukankan      html  css  js  c++  java
  • 如何给input的右上角加个清除的按钮?

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>

    <!-- js引入 -->
    <script type="text/javascript" src="../js/jquery-1.10.2.js" ></script>
    <link href="bootstrap.css" rel="stylesheet">
    <style type="text/css">

    .round {   /*大span*/
        background: #fff none repeat scroll 0 0;
        border: 1px solid #bbb;
        display: inline-block;
        height: 28px;
        margin-right: 2px;
        vertical-align: top;
         175px;
        position: relative;
    }
    .delquery {   /*清除图标*/
        background-position: 0 -320px;
        cursor: pointer;
        height: 20px;
        margin: 4px 0px 0 0;
        position: absolute;
        right: 0;
        top: 0;
         20px;
    }
    .input_key { /*input框*/
        background: #fff none repeat scroll 0 0;
        border: 0 none;
        border-radius: 0;
        font: 16px/22px arial;
        height: 18px;
        margin: 5px 0 0 5px;
        outline: 0 none;
        padding: 0;
         140px;
        background-repeat: no-repeat;
    }
    </style>
    </head>
    <body>
    <table>
        <tr>
            <td>
    <span class="round" id="suggest-align">
            <input type="text" autocomplete="off" maxlength="100" value="" class="input_key" tabindex="1" name="q" id="keyword">
             <span title="清空" class="delquery" id="clear" style="display: none;">x</span>
    </span>
            </td>
        </tr>
    </table>


    </body>
    <script src="./js/jquery.min.js"></script>
    <script type="text/javascript">
    $(function(){
    $("#clear").click(function(){
        $(".input_key").val("");
        $(".input_key").focus();
        $(this).hide();
    })
    $("#keyword").keydown(function(){
        console.log($(".input_key").val())
             if ($(".input_key").val().trim()!="") {
                  $("#clear").show();
              }
    });
    $("#keyword").keyup(function(){
             if ($(".input_key").val().trim()!="") {
                  $("#clear").show();
              }
    });
        
    })

    </script>
    </html>
  • 相关阅读:
    Jmeter+Ant+Jenkins搭建持续集成的接口测试(推荐 Mark)
    配置sonar、jenkins进行持续审查
    查看端口占用
    CentOS 6.5系统上安装SVN服务器端的方法及目录访问权限配置(转总结)
    Windows批处理 调用程序后 不等待子进程 父进程继续执行命令
    Jmeter笔记:响应断言详解
    Ubuntu 16.04常用快捷键
    如何永久激活(破解) IntelliJ IDEA 2018.2
    Cobbler自动化部署
    Typora使用说明(记录总结)
  • 原文地址:https://www.cnblogs.com/sakuar/p/13677540.html
Copyright © 2011-2022 走看看