[英]Is it possible to make font Awesome icon as button in Placeholder?
I've search alot about making normal Font Awesome icon as button in a textbox's Placeholder , but i couldn't find the solution. 我搜索了很多有关在文本框的占位符中将普通的Font Awesome图标制作为按钮的方法,但是我找不到解决方案。
I've designed a login Form has already a Font Awesome icon in placeholder as normal text : 我设计了一个登录表单,在占位符中已经有一个Font Awesome图标作为普通文本:
<input class="form-control" type="password" placeholder='Password '/>
So can i use this icon as button so i can add then Jquery code to show the password later? 所以我可以使用此图标作为按钮,以便稍后添加Jquery代码以显示密码吗?
Demo - CSS and HTML code 演示-CSS和HTML代码
Thank you. 谢谢。
You can used a
tag with position: absolute
您可以使用position: absolute
a
标签
$(document).ready(function(){ $('.hide-password').click(function(){ $(this).toggleClass('show'); }); });
.hide-password { position: absolute; right: 5px; top: 6px; z-index: 10; color: #666; } .hide-password.show .fa:before { content: "\\f06e"; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/> <div class="col-sm-4"> <form class=""> <div class="form-group"> <label class="sr-only" for="exampleInputUser">User</label> <div class="input-group"> <div class="input-group-addon"><i class="fa fa-user"></i></div> <input type="text" class="form-control" id="exampleInputUser" placeholder="User Name"> </div> </div> <div class="form-group"> <label class="sr-only" for="exampleInputPwd">Password</label> <div class="input-group"> <div class="input-group-addon"><i class="fa fa-key"></i></div> <input type="text" class="form-control" id="exampleInputPwd" placeholder="Password"> <a href="javascript:void(0)" class="hide-password"><i class="fa fa-eye-slash"></i></a> </div> </div> <button type="submit" class="btn btn-primary">Sign Up</button> </form> </div>
That's not how you do it. 那不是你做的方式。 Wrap your form control with div and make it position: relative
and inside put an input
and a button
with position: absolute; right: 0;
用div包裹表单控件,并使其position: relative
和内部分别放置一个input
和一个button
,其position: absolute; right: 0;
position: absolute; right: 0;
Hide the button with if($('input').val().length > 0) { $('button').addClass('hidden')}
使用if($('input').val().length > 0) { $('button').addClass('hidden')}
<style>
.input-wrap {position: relative}
.input-wrap > button {position: absolute; right: 0;}
</style>
<script>
$('.input-wrap input').on('keyup', function() {
if($(this).val().length > 0) $(this).next().addClass('hidden');
else $(this).next().removeClass('hidden');
});
</script>
<div class="input-wrap">
<input class="form-control" placeholder="your awesome placeholder">
<button onclick="togglePassVisible()"></button>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.