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);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料