bootstrap密码框显示隐藏
时间: 2023-09-21 18:11:49 浏览: 240
密码显示隐藏
你可以使用以下代码来实现Bootstrap密码框的显示和隐藏功能:
HTML代码:
```html
<div class="form-group">
<label class="col-xs-2 control-label">原始密码:</label>
<div class="col-xs-10">
<div class="block input-icon input-icon-right">
<input name="oldPassword" id="oldPassword" type="password" class="form-control" placeholder="请输入原始密码">
<i class="ace-icon fa fa-eye" title="显示密码" id="see_oldpwd" onclick="seePwd(this)"></i>
</div>
</div>
</div>
```
JavaScript代码:
```javascript
//密码隐藏显示
function seePwd(obj){
var pwdValue = $(obj).parent().children('input:first-child').val(); //获取密码值
var _type = $(obj).parent().children('input:first-child').attr('type'); //获取input的type类型
if(_type == 'password'){
$(obj).parent().children('input:first-child').attr('type','text');
$(obj).attr('class','ace-icon fa fa-eye-slash');
$(obj).attr('title','隐藏密码');
}else if(_type == 'text'){
$(obj).parent().children('input:first-child').attr('type','password');
$(obj).attr('class','ace-icon fa fa-eye');
$(obj).attr('title','显示密码');
}
$(obj).parent().children('input:first-child').val(pwdValue);
}
```
这段代码使用了Bootstrap的样式和JavaScript函数来实现密码框的显示和隐藏。当用户点击密码框后面的眼睛图标时,JavaScript函数`seePwd`会被触发。该函数会获取密码框的值和类型,并根据类型来切换密码框的显示状态。如果密码框的类型为`password`,则将其类型改为`text`,从而显示密码;如果密码框的类型为`text`,则将其类型改回`password`,从而隐藏密码。同时,函数还会更新眼睛图标的样式和标题,以便提示用户当前密码框的状态。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [Bootstrap用户输入密码显示隐藏代码](https://download.csdn.net/download/weixin_38683195/12515022)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [bootstrap显示隐藏密码](https://blog.csdn.net/qq_36134977/article/details/103991162)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文