input框的icon的onclick事件
时间: 2024-04-10 19:28:00 浏览: 20
对于input框的icon的onclick事件,你可以使用以下方法来实现:
1. 首先,给input框的icon元素添加一个唯一的id属性,例如:
```html
<input type="text" id="myInput">
<i id="myIcon" class="fa fa-search"></i>
```
2. 然后,在JavaScript中获取该icon元素,并为其添加onclick事件处理程序,例如:
```javascript
var icon = document.getElementById("myIcon");
icon.onclick = function() {
// 在这里添加你想要执行的代码
console.log("Icon被点击了!");
};
```
在这个例子中,当点击该icon元素时,控制台会输出"Icon被点击了!"。你可以根据需要修改onclick事件的处理程序,执行你想要的操作。
注意:这里使用了Font Awesome图标库(类名为"fa fa-search"),你可以根据你使用的图标库进行相应的修改。
相关问题
帮我写用easyui写一个上传文件的按钮(上传文件是必填的) 然后在后面加一个input框 (隐藏)将上传的文件名称放到input框中
以下是使用 EasyUI 编写一个上传文件按钮,并将上传的文件名称放入隐藏的输入框中的示例代码:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Upload File Example</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/easyui/dist/themes/default/easyui.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/easyui/dist/themes/icon.css">
<script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/easyui/dist/jquery.easyui.min.js"></script>
</head>
<body>
<div>
<input id="fileUpload" type="file" style="display: none;">
<input id="fileName" type="text" style="display: none;">
<a href="#" class="easyui-linkbutton" onclick="openFileUploader()">Upload File</a>
</div>
<script>
function openFileUploader() {
$('#fileUpload').click();
}
$('#fileUpload').change(function() {
var fileName = $(this).val().split('\\').pop();
$('#fileName').val(fileName);
});
</script>
</body>
</html>
```
在上述代码中,我们使用了一个隐藏的文件上传输入框(`<input type="file">`)和一个隐藏的文本输入框(`<input type="text">`)。然后,我们使用 EasyUI 的链接按钮(`<a>`)作为触发器,通过调用 JavaScript 函数 `openFileUploader()` 来打开文件上传对话框。
当用户选择文件后,`fileUpload` 输入框的 `change` 事件将触发,我们从文件路径中提取文件名称,并将其设置为 `fileName` 输入框的值。
你可以根据需要进一步自定义样式和功能。记得在使用此代码之前引入 EasyUI 和 jQuery 的资源文件。
bootstrap密码框显示隐藏
你可以使用以下代码来实现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 ]
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
<input class="easyui-textbox" type="text" name="emails" style="width: 200px;display: none" id="emailId"> 邮箱地址:<input class="easyui-textbox" type="text" name="emails" style="width: 200px;" id="emailInput"> 保存 取消 function saveE() { var emails = $('input[name="emails"]'); console.log(emails); } 这段代码,点击保存时,如何在saveE这个函数内拿到input框中的数据
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
帮我解释这段代码 条码打印 物料编码 <label class="input"> <input type="text" class="input-xs easyui-validatebox" id="txtItemCode"> <input type="hidden" id="hdnItemId" /> </label> 物料名称 <label id="lblItemName"> </label> 物料描述 <label id="lblDescription"></label> 客户 <input type="hidden" id="hdnCustomerId" /> <label id="lblCustomer"></label> 供应商名称 <label class="input" style="width: 95%"> <input type="text" class="input-xs" style="width: 99%" id="txtVendorName" readonly="readonly"> </label>
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)