Retrieve Table Row Index of Current Row

前端 未结 4 1473
执笔经年
执笔经年 2020-12-18 04:49

I am trying to validate a text input when it loses focus. I would like to know which row of the table it is in. This is what I have so far and it keeps coming back as unde

4条回答
  •  青春惊慌失措
    2020-12-18 05:06

    rowIndex is a DOM property, not a jQuery method, so you have to call it on the underlying DOM object:

    tableRow[0].rowIndex
    

    or just:

    var row= this.parentNode.parentNode;
    alert(row.rowIndex);
    

    since you aren't really using jQuery for much there.

    In jQuery 1.4 there is $(row).index(), but it scans siblings to find out which child element number it is in its parent. This is slower and will return a different result to rowIndex in the case where you have multiple ​s.

提交回复
热议问题