首页 > 解决方案 > 如何为特定的 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();

请帮助..谢谢!

标签: javascriptjqueryhtml

解决方案


推荐阅读