假设现在有文本框1和文本框2,1用来输入工号,根据输入的工号值去数据库中的用户表查询对应的姓名,将查询的结果作为文本框2的内容。
1、文本框1加上onChange()方法:
<input type="text" name="account" id="account" style="width: 80px;" onchange="accountToName(this.id)"/>
<input type="text" name="author_name" id="author_name" style="width: 80px;"/>2、查询的sql语句:
select name author_name
from sys_p_user
where account=[account]3、查值填充:
function accountToName(account) {
var gonghao = document.getElementById("account").value;
rdcp.request("!gh/manu/~query/Q_ACCOUNT_TO_NAME", 'account=' + gonghao, function (data) {
author_name = data.body.author_name;
$("#author_name").val(author_name);
});
}
本文介绍了一种通过输入工号自动查询并显示对应姓名的方法。利用JavaScript与HTML结合实现前端交互,通过onChange事件监听工号输入变化,并调用后台接口从数据库中获取员工姓名,最终将结果显示在指定文本框内。
776

被折叠的 条评论
为什么被折叠?



