innerHTML与jquery里的html()区别介绍_jquery

WBOY
Release: 2016-05-16 17:49:12
Original
1127 people have browsed it

看个示例:

复制代码代码如下:

var tbody=document.createElement('tbody');
tbody.innerHTML='IE下tbody的innerHTML是只读的'; //在IE下报错,目标对象错误


现在用jquery的html试试,
复制代码代码如下:

$(tbody).html('IE下tbody的innerHTML是只读的');

发现IE下用jquery能正确显示了,没任何问题。
后来查阅资料才知道,原来IE下tbody、tr这些的innerHTML都是只读的,不允许写入,而在其他浏览器下则没问题。

而jquery里是用了try,catch来检测,如果报错则在catch里重新调用this.empty().append(value),是通过append来添加字符串的。

jquery 如何使用innerHTML

$("#responsediv") 是个Jquery对象,它Val()是对Value属性赋值对它无意义,Jquery没有innerHTML这个属性,应该这样写$("#responsediv")[0].innerHTML=msg 就可以获得这个Dom对象使用innerHTML。

今天在这个基础上加上了一个后加载广告的方法:

代码如下:

Copy after login

百度管家自带的后加载广告的代码,基于jquery

Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!