gpt4 book ai didi

javascript - 连接 1 个字符串和一个 int 值,同时将 id 值赋予在 HTML 中动态生成的

转载 作者:行者123 更新时间:2023-11-28 21:18:39 24 4
gpt4 key购买 nike

var but = document.createElement('span');

but.innerHTML.id="but1"+inc;

but.innerHTML = '<button value="delete row" id="'but'+inc"
onclick="deleteRow(this.id)">delete row</button>';

// '"but"+inc' , "but+inc" are not working

//here inc is an integer value which increments by one

最佳答案

这是错误的

  but.innerHTML.id="but1"+inc;

事情应该是这样的

  but.id="but1"+inc;

but.innerHTML = '<button value="delete row" id="but'+inc+'" onclick="deleteRow(this.id)">delete row</button>';

关于javascript - 连接 1 个字符串和一个 int 值,同时将 id 值赋予在 HTML 中动态生成的 <button> 字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6958486/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com