文本替换

<p id="p1">Hello World!</p>
<div>神经</div>
<h3 class="hh">天黑了</h3>
<table>
<tr><td name="name">你好</td></tr>
</table>

<script>
document.getElementById("p1").innerHTML="已经不是Hello了!";
document.getElementsByName("name")[0].innerText="我不好";
document.getElementsByTagName("div")[0].innerHTML="不是神经";
document.getElementsByClassName("hh")[0].innerText="天亮了";
</script>

PS:  1、innerHTML是符合W3C标准的属性,而innerText只适用于IE浏览器(现在也适应chrome浏览器),因此,尽可能地去使用 innerHTML,而少用innerText

2、innerHTML指的是从对象的起始位置到终止位置的全部内容,包括Html标签。innerText指的是从起始位置到终止位置的内容,但它去除Html标签。

3、innerHTML 是所有浏览器都支持的,innerText 是IE浏览器和chrome 浏览器支持的,Firefox浏览器不支持。

innerHTML,innerText的更多相关文章

  1. innerHtml innerText textContent兼容性问题

    innerHtml,innerText,textContentinnerHtml获取元素带标签的内容:innerText只获取元素的文本:火狐不支持innerText,支持textContent: / ...

  2. innerHTML,innerText,outHTML,outText区别

    <p><div id="div" style="background-color:#ff9966;border:1px #ff0000 dashed;& ...

  3. innerHTML..innerText..textContent

    /* * innerText和textContent 都是设置文字内容的,如果设置的内容当中有标签,也会直接的以文本的方式显示(标签的<>都会按照转义的方式进行解析) * innerTex ...

  4. innerHTML innerText的使用和区别

    document对象中有innerHTML.innerText这两个属性,都是获取document对象文本内容,但使用起来还是有区别的: 1) innerHTML设置或获取标签所包含的HTML+文本信 ...

  5. innerHTML .innerText区别

    ().innerHtml("“):改变html元素: ().innerTEXT(”“):改变文本元素: 试验代码 <!DOCTYPE html> <html lang=&q ...

  6. js 中innerHTML,innerText,outerHTML,outerText的区别

    开头说下innerText和outerText只在chrome浏览器中有效 定义和用法 innerHTML 属性设置或返回表格行的开始和结束标签之间的 HTML,包括标签. 来看代码 <!DOC ...

  7. innerHTML innerText与outerHTML间的区别

    innerHTML与innerText及outerHTML间的区别最容易使初学者搞混淆,为了更好的使读者区分开.下面我就通过一个demo来解释: 代码: <!DOCTYPE html>&l ...

  8. innerHTML,innerText,textContent,outerHTML的用法以及区别

    innerHTML获取的是对象起始的位置到终止位置全部内容,包含html标签. innerText和textContent结果是一样的,不包含标签,直接获取标签内的内容,区别是两者浏览器的兼容性. o ...

  9. javaScript中innerHTML,innerText,outerHTML,outerText的区别

    开头说下innerText和outerText只在chrome浏览器中有效 定义和用法 innerHTML 属性设置或返回表格行的开始和结束标签之间的 HTML,包括标签. 来看代码 <!DOC ...

  10. innerHTML, innerText, outerHTML, outerText的区别

    innerHTML:返回标签内部嵌套的子元素的所有html标签+文本内容content. innerText:返回标签内部嵌套的子元素的文本内容content. outerHTML:返回标签本身+嵌套 ...

随机推荐

  1. 弹性计算服务(Elastic Compute Service) / 云服务器 ECS

    计费方式选择 多种可选择计算费用的方式,可以包年包月,按流量计费,按资源规格计费(本文第四点)等等 地域位置选择 地域:地域指的是 ECS 实例所在的物理位置 地域位置如何选择: 根据访问业务的用户比 ...

  2. 什么样的 SQL 不走索引

    参考: MySQL 索引优化全攻略 索引建立的规则 1.能创建唯一索引就创建唯一索引 2.为经常需要排序.分组和联合操作的字段建立索引 3.为常作为查询条件的字段建立索引 如果某个字段经常用来做查询条 ...

  3. MySQL 连接管理

    目录 MySQL 连接方式 TCP/IP 连接 Socket 连接 MySQL 连接工具 自带连接工具 第三方连接工具 MySQL 连接方式 TCP/IP 连接 # TCP/IP 连接 mysql - ...

  4. vector最最最基础用法(非原创)

    在c++中,vector是一个十分有用的容器,下面对这个容器做一下总结. 1 基本操作 (1)头文件#include<vector>. (2)创建vector对象,vector<in ...

  5. filter_var 函数()绕过执行命令

    escape 过滤器来过滤link,而实际上这里的 escape 过滤器,是用PHP内置函数 htmlspecialchars 来实现的 htmlspecialchars 函数定义如下: htmlsp ...

  6. MATLAB字符串分解, 合并

    % 分解 % regexp s = 'ab/c/d.png' file_name = regexp(s, '/', 'split'); % 'd.png' % split fractions = sp ...

  7. vue & this.$copyText

    vue & this.$copyText click copy https://www.npmjs.com/package/vue-clipboard2 <p>{{message2 ...

  8. ECMAScript 2021 新特性

    ECMAScript 2021 新特性 refs https://codeburst.io/exciting-features-of-javascript-es2021-es12-1de8adf655 ...

  9. free open music API all in one

    free open music API all in one music API SoundCloud xgqfrms · free https://w.soundcloud.com/player/? ...

  10. JSDoc in action

    JSDoc in action JSDoc https://jsdoc.app/index.html https://github.com/jsdoc/jsdoc $ npm -g jsdoc $ n ...