dph6308 2018-08-03 07:01
浏览 244

获取子元素html的id

I have javascript code like this:

<tr id='$stavkaid'>
    <td class='nonEditableData'>$naziv</td>
    <td contenteditable='true' class='editableData' onkeypress='return (event.charCode == 8 || event.charCode == 0 || event.charCode == 13 || event.charCode == 46) ? null : event.charCode >= 48 && event.charCode <= 57' onblur='if(innerHTML.length <= 0) { innerHTML = 0 }else{ innerHTML = innerHTML, checkInput(parentNode.id)}'>$kolicina</td>
    <td contenteditable='true' class='editableData' onkeypress='return (event.charCode == 8 || event.charCode == 0 || event.charCode == 13 || event.charCode == 46) ? null : event.charCode >= 48 && event.charCode <= 57' onblur='if(innerHTML.length <= 0) { innerHTML = 0 }else{ innerHTML = innerHTML, checkInput(parentNode.id)}'>$pcbp</td>
    <td contenteditable='true' class='editableData' onkeypress='return (event.charCode == 8 || event.charCode == 0 || event.charCode == 13 || event.charCode == 46) ? null : event.charCode >= 48 && event.charCode <= 57' onblur='if(innerHTML.length <= 0) { innerHTML = 0 }else{ innerHTML = innerHTML, checkInput(parentNode.id)}'>$rabat</td>
    <td class='nonEditableData'>$pcsp</td>
    <td class='nonEditableData'>$pvsp</td>
</tr>

As you can see inside 3 td i run javascript function checkInput(parentNode.id)

Function looks like this:

function checkInput(stavkaID)
{
    alert(stavkaID);
}

And it works like charm but now what i want is to somehow get values of each row tr where stavkaID is selected one.

So how it went in my head is to somehow inside function i do something like this

function checkInput(stavkaID)
{
    var naziv = getElementById(stavkaID).nowSomehowIdentifyTDWithValueFor(naziv).innerHTML;
    //And like this for other 5 variables
}

I know i can loop through each element of tr with this but problem is identifying td my loop is currently at.

I cannot set id for td since it will be static and next time i create tr it will have same id which is not possible.

  • 写回答

1条回答 默认 最新

  • dongyao1915 2018-08-03 07:03
    关注

    Use this.

    onkeypress="...; checkInput(parentNode.id, this)"
    

    and

    function checkInput(stavkaId, td) {
       console.log(stavkaId, td);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源