分享答案,嘻嘻
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>無標題文檔</title>
</head>
<body>
<div id="content">
? <h1>html</h1>
? <h1>php</h1>
? <h1>javascript</h1>
? <h1>jquery</h1>
? <h1>java</h1>
</div>
<script type="text/javascript">
function clearText() {
? var content=document.getElementById("content");
? // 在此完成該函數
? for(i=0;i<content.childNodes.length;i++){
//? 1. IE全系列、firefox、chrome、opera、safari兼容問題
// 2. 節點之間的空白符,在firefox、chrome、opera、safari瀏覽器是文本節點
? ? ? if(content.childNodes[i].nodeType!=1){
? ? ? ? ? continue;
? ? ? }else{
? ? ? ? ? ?var x=content.removeChild(content.childNodes[i]);
? ? ? ? ? ?x=null;
? ? ? }
? ? ?
? ? ??
? }
??
}
</script>
<button onclick="clearText()">清除節點內容</button>
</body>
</html>
2022-03-25
親,在電商二期中有規劃,因為一期主要是想帶你們把前后臺流程跑通,如果是一個真實現的電商網站,會有很多的模塊,這些都會在二期中講解的。同學您好,您只要安裝DW軟件就可以練習的。
2019-03-25
實現了,不知道科學不
function clearText() {
var content=document.getElementById("content");
// 在此完成該函數
mylength=content.childNodes.length;
for (var i=1; i<mylength; i++){
content.removeChild(content.childNodes[i]);?
}
2019-02-12
content.childNodes.length??
if(content.childNodes[i].nodeType!=1){
? ? ? ? ? continue;
2019-02-10
666