当前位置:网站首页>Oninput one function to control multiple oninputs (take the contents of this input box as parameters) [very practical, very practical]

Oninput one function to control multiple oninputs (take the contents of this input box as parameters) [very practical, very practical]

2022-04-23 17:11:00 ZHZHK001

effect
oninput Take the contents of this input box as a parameter , Take the input box of the operation object as the parameter
One function can control multiple functions oninput The effect of
Knowledge point
1. Function encapsulation , The ginseng
2.this Usage of
3.getAttribute Usage of

The effect is as shown in the picture
 Insert picture description here
The key codes are as follows

	<tr>
			<td>ID1</td>
			<td>
				<input id="P_PID" oninput="gainPName(this,'NAME1')" />
			</td>

			<td> name 1</td>
			<td>
				<input id="NAME1" />
			</td>
		</tr>

		<tr>
			<td>ID2</td>
			<td>
				<input id="P_FID" oninput="gainPName(this,'NAME2')" />
			</td>

			<td> name 2</td>
			<td>
				<input id="NAME2" />
			</td>

			<td>ID3</td>
			<td>
				<input id="P_MID" oninput="gainPName(this,'NAME3')" />
			</td>

			<td> name 3</td>
			<td>
				<input id="NAME3" />
			</td>
		</tr>


 /** *  Get... In real time ID Personnel information , And change the value of the corresponding input box  * @param input  This input box  * @param toNameID  Of another input box ID */
    function gainPName(input,toNameID){
    
      // console.log(input); // Get the contents of this input box 
      // console.log(input.getAttribute("ID")); // Get the of this input box ID
      // console.log( $("#"+input.getAttribute("ID") ).val() ); // Get the input content of this input box 
        $("#"+toNameID).val(" unregistered ");  // Assign initial value to 
        var result = gainPersonById(  $("#"+input.getAttribute("ID")   ).val()      );
        if(result.length==0){
    
            $("#"+toNameID).val(" unregistered ");
        }else{
    
            if(result.get("flag")){
    
                    $("#"+toNameID).val(result.get("rs").NAME);
            }else{
    
                $("#"+toNameID).val(" unregistered ");
            }
        }
    }

版权声明
本文为[ZHZHK001]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230553251729.html