<html>
<head>
<title>Text Node Modifications</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
</head>
<body>
<p id="p1">This is a test</p>
<script type="text/javascript">
<!--
var textNode = document.getElementById('p1').firstChild;
//-->
</script>
<form action="#" method="get">
<input type="button" value="show" οnclick="alert(textNode.data);" />
<input type="button" value="length" οnclick="alert(textNode.length);" />
<input type="button" value="change" οnclick="textNode.data = 'Now a new value!'" />
<input type="button" value="append" οnclick="textNode.appendData(' added to the end');" />
<input type="button" value="insert" οnclick="textNode.insertData(0,'added to the front');" />
<input type="button" value="delete" οnclick="textNode.deleteData(0, 2);" />
<input type="button" value="replace" οnclick="textNode.replaceData(0,4,'Zap!');"/>
<input type="button" value="substring" οnclick="alert(textNode.substringData(2,2));" />
<input type="button" value="split" οnclick="temp = textNode.splitText(5); alert('Text node ='+textNode.data+'\nSplit Value = '+temp.data);" />
</form>
</body>
</html>
dom修改综合实例
最新推荐文章于 2019-04-10 16:56:44 发布