如何使用onblur在相邻单元上调用方法

How to call method on adjacent cell with onblur?

本文关键字:单元 调用 方法 何使用 onblur      更新时间:2023-09-26

我试图将验证添加到用户将输入数据的表中。我试图收集的信息是轮班时间,在轮班开始和结束时不能有间隙(出3:59,4:00是我正在寻找的)。当用户编辑移位时间时,我希望能够查看相邻单元格并自动调整该单元格的时间。

因此,如果第二班次开始时间从14:00更改为13:00,我应该查看第二班次结束时间和第一班次结束时间,并相应地调整这些时间并继续查看,直到没有更多更改。

是否有一种方法可以在相邻的单元格上调用方法?

这是用HTML,经典ASP和Javascript编写的。

<table border='1' style='border-collapse:collapse;'>
    <tr>
        <th>Name</th>
        <th>Start</th>
        <th>End</th>
    </tr>
    <tr>
        <td style='width: auto;'><Input style='border-style:none; width: auto;' Type='Text' Name='cntl0Name' Value='First' onBlur='updateGrid("Name", cntl0Name, "0", "First", "06:00", "13:59", 1);'></td>
        <td style='width: auto;'><Input style='border-style:none; width: auto;' Type='Text' Name='cntl0Start' Value='06:00' onBlur='updateGrid("Start", cntl0Start, "0", "First", "06:00", "13:59", 1);'></td>
        <td style='width: auto;'><Input style='border-style:none; width: auto;' Type='Text' Name='cntl0End' Value='13:59' onBlur='updateGrid("End", cntl0End, "0", "First", "06:00", "13:59", 1);'></td>
    </tr>
    <tr>
        <td style='width: auto;'><Input style='border-style:none; width: auto;' Type='Text' Name='cntl1Name' Value='Second' onBlur='updateGrid("Name", cntl1Name, "1", "Second", "14:00", "21:59", 1);'></td>
        <td style='width: auto;'><Input style='border-style:none; width: auto;' Type='Text' Name='cntl1Start' Value='14:00' onBlur='updateGrid("Start", cntl1Start, "1", "Second", "14:00", "21:59", 1);'></td>
        <td style='width: auto;'><Input style='border-style:none; width: auto;' Type='Text' Name='cntl1End' Value='21:59' onBlur='updateGrid("End", cntl1End, "1", "Second", "14:00", "21:59", 1);'></td>
    </tr>
    <tr>
        <td style='width: auto;'><Input style='border-style:none; width: auto;' Type='Text' Name='cntl2Name' Value='Third' onBlur='updateGrid("Name", cntl2Name, "2", "Third", "22:00", "05:59", 1);'></td>
        <td style='width: auto;'><Input style='border-style:none; width: auto;' Type='Text' Name='cntl2Start' Value='22:00' onBlur='updateGrid("Start", cntl2Start, "2", "Third", "22:00", "05:59", 1);'></td>
        <td style='width: auto;'><Input style='border-style:none; width: auto;' Type='Text' Name='cntl2End' Value='05:59' onBlur='updateGrid("End", cntl2End, "2", "Third", "22:00", "05:59", 1);'></td>
    </tr>
</table>

是的,你可以使用previousSibling和nextSibling DOM属性来访问相邻的单元格。

this.previousSibling。value 将给你以前的单元格值和this.nextSibling。value将给出下一个单元格值