无法将左侧赋值作为连接操作的一部分。

huangapple go评论55阅读模式
英文:

Invalid left-hand side in assignment while concatenating

问题

function nowakolumna(){
    document.getElementById("listacen").innerHTML += '<tr><td><input type="text"></td><td><input type="text"></td></tr>';
}
英文:
function nowakolumna(){
    document.getElementById(&quot;listacen&quot;) += &#39;&lt;tr&gt;&lt;td&gt;&lt;input type=&quot;text&quot;&gt;&lt;/td&gt;&lt;td&gt;&lt;input type=&quot;text&quot;&gt;&lt;/td&gt;&lt;/tr&gt;&#39;;
}

i have this code for adding new column in table but when i try to execute it via button with onclick listener i get this error: Invalid left-hand side in assignment. Anyone help.

答案1

得分: 1

你不能这样做。文档元素对象上未定义 += 操作符。你需要这样做:

function nowakolumna() {
    document.getElementById("listacen").innerHTML += '<tr><td><input type="text"></td><td><input type="text"></td></tr>';
}
英文:

You cannot do that. Operator += on a document element object is not defined. You have to do this:

function nowakolumna() {
    document.getElementById(&quot;listacen&quot;).innerHTML += &#39;&lt;tr&gt;&lt;td&gt;&lt;input type=&quot;text&quot;&gt;&lt;/td&gt;&lt;td&gt;&lt;input type=&quot;text&quot;&gt;&lt;/td&gt;&lt;/tr&gt;&#39;;
}

huangapple
  • 本文由 发表于 2023年7月7日 05:51:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76632720.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定