带有删除的input框

效果图
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

代码

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

    <!-- js引入 -->
    <script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.4.min.js"></script>
    <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;
            width: 175px;
            position: relative;
        }
        .delquery {   /*清除图标*/
            background-position: 0 -320px;
            cursor: pointer;
            height: 20px;
            margin: 4px 0px 0 0;
            position: absolute;
            right: 0;
            top: 0;
            width: 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;
            width: 140px;
            background-repeat: no-repeat;
        }
    </style>
</head>
<body>
<h1>监听_input值的变化</h1>

<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 type="text/javascript">
    $("#clear").click(function(){
        $(".input_key").val("");
        $(".input_key").focus();
        $(this).hide();
    })
    $("#keyword").keydown(function(){
        if ($(".input_key").val().trim()!="") {
            $("#clear").show();
        }
    });
    $("#keyword").keyup(function(){
        if ($(".input_key").val().trim()!="") {
            $("#clear").show();
        }
    });



</script>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值