JS 隐藏同级的元素后只显示JS文件
demo.html
<!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <p>头部信息</p> <div> <p>阅谁问君诵水落</p> <p>阅谁问君<p>阅谁问君诵水落</p> <p>阅谁问君诵水落</p><p>阅谁问君诵水落诵水落</p> <p>阅谁问君<p>阅谁问君诵水落</p><p>阅谁问君诵水落</p><p>阅谁问君诵水落</p><p>诵水落</p> <p>阅谁问君诵水落</p> <p>阅谁问君诵水落<p>阅谁问君诵水落</p><p>阅谁问君诵水落</p> <script type="text/javascript" src="demo.js"></script> <p>阅谁问君诵水落</p> <p>阅谁问君诵水落</p> <p>阅谁问君诵水落</p> <p>阅谁问君诵水落</p> <p>阅谁问君诵水落<p>阅谁问君诵水落</p><p>阅谁问君诵水落</p> </div> <p>备案信息</p> </body> </html>
demo.js
document.writeln("<div id=\"contSonOnly\">"); document.writeln("<p>内容内容内容内容内容内容内容内容内容</p>"); document.writeln("</div>"); window.onload=function(){ var contSonOnly=document.getElementById("contSonOnly"); var contParent=contSonOnly.parentNode; var contSonList=contParent.children; for(var i=0;i<contSonList.length;i++){ if(contSonList[i]!=contSonOnly){ contSonList[i].style.display="none"; } } }
效果图:
相关推荐
阿斌Elements 2020-06-11
gufudhn 2020-06-06
88274956 2020-11-03
Zhongmeishijue 2020-09-10
runner 2020-09-01
梦的天空 2020-08-25
IdeaElements 2020-08-19
luvhl 2020-08-17
移动开发与培训 2020-08-16
ReunionIsland 2020-08-16
lyqdanang 2020-08-16
NARUTOLUOLUO 2020-08-03
MyNameIsXiaoLai 2020-07-08
星辰的笔记 2020-07-04
csstpeixun 2020-06-28
letheashura 2020-06-26
liaoxuewu 2020-06-26
OldBowl 2020-06-26
北京老苏 2020-06-25