gpt4 book ai didi

javascript - 如何获取输入字段中的javascript函数参数值

转载 作者:行者123 更新时间:2023-12-03 04:06:24 25 4
gpt4 key购买 nike

var tbl = document.getElementById("tblMain");
if (tbl != null) {
for (var i = 0; i < tbl.rows.length; i++) {
for (var j = 0; j < tbl.rows[i].cells.length; j++)
tbl.rows[i].cells[j].onclick = function () { getval(this); };
}
}

function getval(cel) {
alert(cel.innerHTML);
}

$("#tblMain tbody td").on('click', function() {
$("#empname").val($(this).text());


$("#empname").on(function () {
if (this.value.length == this.maxLength) {
$(this).next('#empname').focus();
}
});
<table align="center" id="tblMain" border="1" style="cursor: pointer;">
<tr>
<td>
1
</td>
<td>
2
</td>
<td>
3
</td>
<td>
4
</td>
</tr>
<tr>
<td>
5
</td>
<td>
6
</td>
<td>
7
</td>
<td>
8
</td>
</tr>
<tr>
<td>
9
</td>
<td>
0
</td>
<td>
R3C3
</td>
<td>
R3C4
</td>
</tr>
<tr>
<td>
R4C1
</td>
<td>
R4C2
</td>
<td>
R4C3
</td>
<td>
R4C4
</td>
</tr>
</table>
<input type="text" id="empname" maxlength="1">
<input id="empname2" type="text" maxlength="1" />
cxxxxxxxxxxxxxxxxxxxxxxxxfhdfxdzdzdzdzdzdzfdzffzdfzdzdzdzdzdzcxxxxxxxxxxxxxxxxxxxxxxxxfhdfxdzdzdzdzdzdzfdzffzdfzdzdzdzdzdzcxxxxxxxxxxxxxxxxxxxxxxxxfhdfxdzdzdzdzdzdzfdzffzdfzdzdzdzdzdzcxxxxxxxxxxxxxxxxxxxxxxxxfhdfxdzdzdzdzdzdzfdzffzdfzdzdzdzdzdzcxxxxxxxxxxxxxxxxxxxxxxxxfhdfxdzdzdzdzdzdzfdzffzdfzdzdzdzdzdzcxxxxxxxxxxxxxxxxxxxxxxxxfhdfxdzdzdzdzdzdzfdzffzdfzdzdzdzdzdzcxxxxxxxxxxxxxxxxxxxxxxxxfhdfxdzdzdzdzdzdzfdzffzdfzdzdzdzdzdzcxxxxxxxxxxxxxxxxxxxxxxxxfhdfxdzdzdzdzdzdzfdzffzdfzdzdzdzdzdzcxxxxxxxxxxxxxxxxxxxxxxxxfhdfxdzdzdzdzdzdzfdzffzdfzdzdzdzdzdzcxxxxxxxxxxxxxxxxxxxxxxxxfhdfxdzdzdzdzdzdzfdzffzdfzdzdzdzdzdzcxxxxxxxxxxxxxxxxxxxxxxxxfhdfxdzdzdzdzdzdzfdzffzdfzdzdzdzdzdzcxxxxxxxxxxxxxxxxxxxxxxxxfhdfxdzdzdzdzdzdzfdzffzdfzdzdzdzdzdzcxxxxxxxxxxxxxxxxxxxxxxxxfhdfxdzdzdzdzdzdzfdzffzdfzdzdzdzdzdzcxxxxxxxxxxxxxxxxxxxxxxxxfhdfxdzdzdzdzdzdzfdzffzdfzdzdzdzdzdzcxxxxxxxxxxxxxxxxxxxxxxxxfhdfxdzdzdzdzdzdzfdzffzdfzdzdzdzdzdzcxxxxxxxxxxxxxxxxxxxxxxxxfhdfxdzdzdzdzdzdzfdzffzdfzdzdzdzdzdz

最佳答案

您缺少一些结束括号和大括号。当您调试 javascript 时,请检查错误控制台(如果在 Chrome 中,请按 F12)。这是您的 javascript,其中缺少字符:

var tbl = document.getElementById("tblMain");
if (tbl != null) {
for (var i = 0; i < tbl.rows.length; i++) {
for (var j = 0; j < tbl.rows[i].cells.length; j++)
tbl.rows[i].cells[j].onclick = function () { getval(this); };
}
}

function getval(cel) {
alert(cel.innerHTML);
}

$("#tblMain tbody td").on('click', function() {
$("#empname").val($(this).text());
});

$("#empname").on(function () {
if (this.value.length == this.maxLength) {
$(this).next('#empname').focus();
}
});

你确实可以删除很多 Javascript 代码。也许您拥有所有顶级的东西只是为了测试?或者另一种分配 onclick 处理的形式?你真正需要的只是下半场。 JQuery 的东西。虽然我不完全确定你想对第二个做什么。 https://jsfiddle.net/c5n4h9zu/1/

关于javascript - 如何获取输入字段中的javascript函数参数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44532019/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com