当前位置:网站首页>oninput 一个函数达到控制多个oninput的效果(将本输入框的内容作为参数)【很实用,很实用】
oninput 一个函数达到控制多个oninput的效果(将本输入框的内容作为参数)【很实用,很实用】
2022-04-23 05:55:00 【ZHZHK001】
效果
oninput 将本输入框的内容作为参数,将操作对象的输入框作为参数
一个函数达到控制多个oninput的效果
知识点
1.函数封装,传参
2.this的用法
3.getAttribute的用法
效果如图
关键代码如下
<tr>
<td>ID1</td>
<td>
<input id="P_PID" oninput="gainPName(this,'NAME1')" />
</td>
<td>名称1</td>
<td>
<input id="NAME1" />
</td>
</tr>
<tr>
<td>ID2</td>
<td>
<input id="P_FID" oninput="gainPName(this,'NAME2')" />
</td>
<td>名称2</td>
<td>
<input id="NAME2" />
</td>
<td>ID3</td>
<td>
<input id="P_MID" oninput="gainPName(this,'NAME3')" />
</td>
<td>名称3</td>
<td>
<input id="NAME3" />
</td>
</tr>
/** * 实时获取ID的人员信息,并且更改对应的输入框的取值 * @param input 本输入框 * @param toNameID 另一个输入框的ID */
function gainPName(input,toNameID){
// console.log(input); //获取这个输入框的内容
// console.log(input.getAttribute("ID")); //获取这个输入框的ID
// console.log( $("#"+input.getAttribute("ID") ).val() ); //获取本输入框的输入的内容
$("#"+toNameID).val("未登记"); //赋初值
var result = gainPersonById( $("#"+input.getAttribute("ID") ).val() );
if(result.length==0){
$("#"+toNameID).val("未登记");
}else{
if(result.get("flag")){
$("#"+toNameID).val(result.get("rs").NAME);
}else{
$("#"+toNameID).val("未登记");
}
}
}
版权声明
本文为[ZHZHK001]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_43142925/article/details/105591746
边栏推荐
猜你喜欢
随机推荐
excel快速自动填充空白单元格上一行的内容
js根据名字将数组对象中名字相同的项组成一个相同的数组
Interprocess communication - mutex
Redux概述
元编程,代理Proxy与反射Reflect
往String原型上封装一个时间戳转日期的方法
查漏补缺(三)
Sdoi2009-hh Necklace
2022ldu winter vacation training - program patch
C language structure specifying initialization
excel里有文字的数字怎么从小到大排序,而不是首数字排序
算数表达式
说说ts的心里话
Vs can be compiled, but there will be a red underline to indicate the problem of undefined identifiers
ECMAScript历史
【正河源刀具相关】
Makefile foundation, common functions and general makefile
The use of volatile in C language
SQLite3 encrypted version
token详解以及应用原理