[html] 如何给input的右上角加个清除的按钮?
<title>Insert title here</title> <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>
<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>
个人简介
我是歌谣,欢迎和大家一起交流前后端知识。放弃很容易,
但坚持一定很酷。欢迎大家一起讨论
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现