jsにおけるvalue、inners HTML、innerTextとtextContentの違い
6096 ワード
<html lang="en">
<head>
<meta charset="UTF-8">
<title> title>
<style type="text/css">
div{
width:300px;
height:300px;
float:left;
border:1px solid blue;
margin-left:50px;
}
style>
head>
<body>
<div><p>i love youp>div>
<div>div>
<div>div>
<div>div>
<div>
<p>J
p>
<a href="http://www.xxoo.com">xx ooa>
div>
<div>div>
<script type="text/javascript">
var divs=document.getElementsByTagName('div');
/*
value : ---textarea
innerHTML: , html , html
innerText: , html
textContent: , html
*/
//
console.log(divs[0].innerHTML);
console.log(divs[0].innerText);
console.log(divs[0].textContent);
//
divs[1].innerHTML='i miss you
';
divs[2].innerText='i miss you
';
divs[3].textContent='i miss you
';
/*
innerText textContent
innerText html
textContent
*/
console.log('%c'+divs[4].innerText,'color:red;');
console.log(divs[4].textContent);
var str="
xx oo";
// divs[5].innerText=str;
// divs[5].textContent=str;
script>
body>
html>