1 回答

TA貢獻(xiàn)1790條經(jīng)驗(yàn) 獲得超9個(gè)贊
找childNodes把,判斷是文本節(jié)點(diǎn)看里面有沒有類容,有就干掉
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<p onclick="aaa(this)">
<i>1111</i>
aaaaaaa
</p>
<script>
function aaa(obj){
for(el of obj.childNodes){
if(el.nodeType==3&&!!el.nodeValue.replace(/\s+/g,'')){
console.log(el)
el.nodeValue = ''
}
}
}
</script>
</body>
</html>
添加回答
舉報(bào)