类似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;
    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>
            <input type="text"/>
        </td>
    </tr>
    <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">
$(function(){
$("#clear").click(function(){
    $(".input_key").val("");
    $(".input_key").focus();
    $(this).hide();
})
/* var tValue;
setInterval(function(){
       if(tValue !=$("#keyword").val()){ //这里写自己的业务逻辑代码
           if ($(".input_key").val().trim()!="") {
                $("#clear").show();
            }
         tValue =$("#keyword").val();
       }
},100); */
var tValue;
$("#keyword").keydown(function(){
         if ($(".input_key").val().trim()!="") {
              $("#clear").show();
          }
});
$("#keyword").keyup(function(){
         if ($(".input_key").val().trim()!="") {
              $("#clear").show();
          }
});

})

</script>
</html>
时间: 2024-08-07 01:27:09

类似input框内最右边添加图标,有清空功能的相关文章

IE下input框内有一把小叉子

IE浏览器中,使用datepicker插件时,input选择框出现了一把小叉号,而其他浏览器运行正常 这个时候只需要在CSS中添加 input::-ms-clear{display: none;} 就可以解决,也可以通过CSS3中的属性选择器针对特定选择框进行处理,比如: input[type=search]::-ms-clear{display: none;}  /*清除IE下的 search 叉号*/ input[type=text]::-ms-clear{display: none;}  

关于JS将图片回显问题,将byte[]转化为流,信息填入input框内

1 <script> 2 3 var For_photo = [] 4 var normal_data = new Object(); 5 var Userinfo = JSON.parse(sessionStorage.getItem('Userinformation')); 6 for (var prop in Userinfo) { 7 //$("[name='" + prop + "']").val(ForeignTeachers[prop]);

input框添加图标,代替submit

input框添加图标,代替submit的意思是form表单中,将常规的提交按钮更改成图标,但是图标具有提交的功能 首先,我们先探讨下如何获取图标,我是从阿里巴巴图标库中下载的,因为改版的原因,网上的一些方法并不能保证下载下来完整的代码,所以我来贴一下具体的图片,说明下如何下载代码 进入官网,搜索需要的内容,加入购物车,下载源码步骤不同就在后面 点击添加至项目,选择下载至本地 下载完成后是一个压缩包,解压后,将红色框的字体文件添加到font文件夹,因为大家可以轻而易举的发现,这是四种不同的字体编码

bootstrap在input框中加入icon图标

<form class="form-horizontal"> <div class="form-group has-feedback"> <div class="username"> <span class="fa fa-user-circle-o fa-2x form-control-feedback"></span> <input type="te

JavaScript---网络编程(11)--DHTML技术演示(4)-单选框/下拉菜单/添加文件

本节讲述单选框/下拉菜单/添加文件,综合css,html和JavaScript. 单选框: 实现的功能是:(类似平时的性格测试) 先隐藏一部分页面,然后通过点击单选框来显示. 再通过选项的选择-(每个选项有不同的积分)积分的多少来给出评语 演示代码: <html> <head> <title>DHTML技术演示---radio的使用</title> <meta http-equiv="content-Type" content=&q

robot framework :获取原有文本编辑框内的数据,然后在原有数据的基础上在赋值

需要实现的功能:获取原有文本编辑框内的数据,然后在原有数据的基础上在赋值 备注:由于自己是个新手,所以只能利用最笨的方式来实现.如果以后有的更方便的实现方式,则再更新. 操作: ${text}    Get Value    [ locator ]                #获取文本框内的原有的数据 log    ${text} Input Text    [ locator ]    ${text}测试          #获取原有的数据后,在原有数据的基础上添加新的数据

input框处理删除小图标的功能

/** * 搜索中的删除小图标功能与按backspace键删内容时事件,用于清空搜索框内的文字: * inputId:表单ID名称 如:searchKeys */ _clearSearchInput: function (inputId) { if (typeof inputId != "string") { return; } //input焦点 var input_Focus = $("#" + inputId); //console.log(input_Foc

解决element组件input框的autofocus只触发一次

<i class="icon iconfont icon-edit-p" v-if="!editAtlasBool" @click="showInput"></i> <el-input v-if="editAtlasBool" :placeholder="newAtlasName" ref="atlas-name-input" v-model="a

浅谈asp.net通过本机cookie仿百度(google)实现搜索input框自动弹出搜索提示

对于通过用户输入关键词实现自动弹出相关搜索结果,这里本人给两种解决方案,用于两种不同的情形. 常见方法是在数据库里建一个用户搜索关系表,然后通过用户搜索框输入的关键字异步调用数据表中的相关数据,显示在一个隐藏div中. 第二种方式也就是我现在着重讨论的方式,适用于单个用户,基于此用户以往的搜索数据来实现搜索提示功能.技术关键是记录下用户的以往搜索数据,写入cookie,然后页面从用户本机cookie调用数据. ok,下面进入正题.本文主要讲实现步骤,代码可根据自己实际需要更改. 一,如何写入co