开发者

concatinating 1 string and an int value while giving id value to a <button> field which is generated dynamically in HTML

开发者 https://www.devze.com 2023-03-26 08:45 出处:网络
var bu开发者_高级运维t = document.createElement(\'span\'); but.innerHTML.id=\"but1\"+inc; but.innerHTML = \'<button value=\"delete row\" id=\"\'but\'+inc\"
var bu开发者_高级运维t = 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


this is wrong

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

this is how it should be

  but.id="but1"+inc;

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

精彩评论

暂无评论...
验证码 换一张
取 消