日期:2014-05-16  浏览次数:20727 次

Jquery中Append与html与innerHtml的区别 - Web 开发 / Ajax
刚学Jquery啊,请各位高手指教。 Jquery中,Append,html,innerHtml三者的用法和区别

------解决方案--------------------
.append( content )
content一个元素,HTML字符串,或者jQuery对象,用来插在每个匹配元素里面的末尾。
version added: 1.4.append( function(index, html) )
function(index, html)一个返回HTML字符串的函数,该字符串用来插入到匹配元素的末尾。 Receives the index position of the element in the set and the old HTML value of the element as arguments.


.html() 返回: String

从匹配的第一个元素中获取HTML内容。

version added: 1.0.html()



.innerHTML 是js的原生方法,指容器内部的html例如
<div>内容内容<span>内容</span></div>
------解决方案--------------------
append()方法插入指定在结束(但还在里面)选定的元素的内容。
html更改所选元素的(内部)的HTML

------解决方案--------------------
append()是添加子节点
html()和innerhtml作用一样 在容器中添加要添加的代码
有时只能用append 比如table 不能用html和innerhtml