实现input输入框自带清除按钮


<div style="display:inline-block;position:relative;">  
  <div style="position:absolute;right:2px;top:-2px;cursor:pointer;display:none;" class="input_clear">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">X</button>
   </div>  
   <input type="text" placeholder="请输入" class="input-text w200 form-control" aria-describedby="basic-addon1" name="keyword" id="keyword" style="height:35px;" >  
</div>

 

<script>
        $("input").focus(function(){  
    $(this).parent().children(".input_clear").show();  
});  
$("input").blur(function(){  
    if($(this).val()=='')  
    {  
        $(this).parent().children(".input_clear").hide();  
    }  
});  
$(".input_clear").click(function(){  
    $(this).parent().find('input').val('');  
    $(this).hide();  
}); 
        </script>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM