javascript - 如何为特定的 HTML 表格列应用 focus()?
问题描述
如果用户在 HTML 表格列中输入无效数据,我需要应用 focus() 函数。
请在下面找到我的 JavaScript 函数:
function validate(tableID)
{
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var rows=table.rows;
var data = [];
var cells;
for (var n = 1; n < rowCount; n++) {
cells = rows[n].cells;
data.push([
cells[0].firstElementChild.checked,
cells[1].firstElementChild.value,
cells[2].firstElementChild.value,
cells[3].firstElementChild.value,
cells[4].firstElementChild.value
]);
if (regex1.test(cells[3].firstElementChild.value) == false) {
alert('Please enter valid pan number');
document.getElementById('txtRow3').rows[n].cells[3].focus();
return false;
}
}
在上面的函数中,如果用户输入了无效数据,我尝试使用下面的行来关注表格行的第四个单元格。但它不起作用。document.getElementById('txtRow3').rows[n].cells[3].focus();
请帮助..谢谢!
解决方案
推荐阅读
- python - 在数据框上使用 .apply() 将我的列重新排序为字母顺序?奇怪的行为
- java - Head First Java书战舰游戏
- angular - 创建要显示的格式化时间列表
- r - R中的正则表达式:从字符串中提取单词
- docker - 无法在远程主机上构建 docker 容器
- mysql - 如何将相关表的多个总和引用为子查询
- mysql - 有没有更快的方法来搜索在另一个表中有记录的记录?
- javascript - VueJs 动态按钮值
- sql - 不能同时为空的多个列的唯一约束
- amazon-cloudformation - 如何在 CloudFormation 模板中创建一些随机或唯一值?