分享答案,嘻嘻
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>無標(biāo)題文檔</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");
? // 在此完成該函數(shù)
? for(i=0;i<content.childNodes.length;i++){
//? 1. IE全系列、firefox、chrome、opera、safari兼容問題
// 2. 節(jié)點(diǎn)之間的空白符,在firefox、chrome、opera、safari瀏覽器是文本節(jié)點(diǎn)
? ? ? if(content.childNodes[i].nodeType!=1){
? ? ? ? ? continue;
? ? ? }else{
? ? ? ? ? ?var x=content.removeChild(content.childNodes[i]);
? ? ? ? ? ?x=null;
? ? ? }
? ? ?
? ? ??
? }
??
}
</script>
<button onclick="clearText()">清除節(jié)點(diǎn)內(nèi)容</button>
</body>
</html>
2022-03-25
親,在電商二期中有規(guī)劃,因?yàn)橐黄谥饕窍霂銈儼亚昂笈_(tái)流程跑通,如果是一個(gè)真實(shí)現(xiàn)的電商網(wǎng)站,會(huì)有很多的模塊,這些都會(huì)在二期中講解的。同學(xué)您好,您只要安裝DW軟件就可以練習(xí)的。
2019-03-25
實(shí)現(xiàn)了,不知道科學(xué)不
function clearText() {
var content=document.getElementById("content");
// 在此完成該函數(shù)
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