我已经阅读了一些专门与innerHTML= vs .html()有关的问题。但还没有将任何内容添加到变量中,例如将innerHTML+=添加到html()中。是否有一个 jquery 事件可以添加多个 html 字符串?或者我现在应该依赖innerHTML+=?
最能描述当前问题的编码:
var pushy = ['blah', 'blaH', 'blaah'];
for(i=0;i<pushy.length;i++){
document.getElementById("demo").innerHTML +=
"<div>Im one heck of a div and more!</div>" + pushy[i];}
对比
$("#demo").html("<div>Im one heck of a div and more!</div>" + pushy[i]);
//where it will return the last array value and not the first value
虽然第一个是转到和故障保护。但想要看到与仅弹出数组的最后一个值完全等效的内容。这是我的innerHTML+= vs .html()例如。问题不在于innerHTML =
,而在于其+=
。
最佳答案
关于javascript - 用于数组 html 插入的 jquery 版本 ".innerHTML +=",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50712047/