document.getElementById("myList").appendChild(str)
看这个链接:网页链接
希望可以帮到你,望采纳~
<script>window.onload=function(){
var btn=document.createElement("button")
btn.innerHTML="btn"
document.body.appendChild(btn)
}
</script>
或者
<script>
window.onload=function(){
document.body.innerHTML+="<button>btn</button>"
}
</script>
第一种方法 , 用连接符“+”把要连接的字符串连起来:
str="a"
str+="b"
第二种方法, 以数组作为中介用 join 连接字符串:
var arr=new Array()
arr.push(a)
arr.push(b)var str=arr.join("")
第三种方法, 利用对象属性来连接字符串:
function stringConnect(){ this._str_=new Array()
}
stringConnect.prototype.append=function(a){ this._str_.push(a)
}
stringConnect.prototype.toString=function(){ return this._str_.join()
} var mystr=new stringConnect
mystr.append("a") var str=mystr.toString()
JS中三种字符串连接方式的性能比较:
第一种,方法毫无疑问是最便捷快速的,如果只连接100个以下的字符串建议用这种方法最方便;
第二种,这种方法要比第一种消耗更少的资源,速度也更快;
第三种,方法加入了随机参数,应该是避免了缓存的影响的。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)