爱易网
IT新闻
IT新闻
爱易资讯
网站搭建
云虚拟主机教程
云服务器教程
Apache教程
IIS教程
Nginx教程
网站策划
站长文章
推广教程
淘宝客教程
网页设计
HTML教程
XHTML教程
CSS教程
HTML5教程
CSS3教程
JavaSript基础
JQuery教程
Node.js教程
前端技术
Ajax教程
Js特效
Xml教程
平面设计
页面UI设计
photoshop教程
程序开发
AI人工智能
Asp教程
Php教程
Asp.Net教程
Net Core教程
C#教程
Java教程
Jsp教程
开发技术
微信小程序教程
Uniapp开发教程
微信公众号开发
Andriod教程
IOS教程
DOS教程
Python教程
Docker教程
Windows Container教程
数据库
MSSQL教程
MySQL教程
Redis教程
Access教程
Oracle教程
数据库教程
操作系统
Linux教程
Windows教程
MAC教程
Cisco教程
交换机教程
防火墙教程
搜索
爱易网页
JS特效
JS获取对象代码示例
JS获取对象代码示例
日期:2014-05-18 浏览次数:20204 次
以下是HTML网页特效代码,点击运行按钮可查看效果:
以下是程序代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>javascript获取对象封装</title> <style type="text/css" media="all"> #test{ width:600px; height:auto; overflow:hidden; padding:9px; border:#FF0000 1px solid; background-color:#F0F0F0; } ul{ border:#FFCC33 1px solid; height:auto; overflow:hidden; width:560px; background-color:#666666; color:#FFFFFF; margin:6px 0px; padding:6px; list-style-type:circle; } .test2{ background-color:#999999; color:#333333; } input{ height:22px; border:#FF9933 1px solid; overflow:hidden; cursor:pointer; } </style> <script language="javascript" type="text/javascript"> /*-------------封装开始------------------*/ function GetId(id){return document.getElementById(id)} //通过ID获取对象 function GetTag(tag){return document.getElementsByTagName(tag)} //通过Tag获取对象 function GetChildTag(id,tag){return id.getElementsByTagName(tag)} //通过Tag获取ID的子对象 function GetClass(className){return getElementsByClassName(className)} //通过className获取对象 var $c=function(array){var nArray = [];for (var i=0;i<array.length;i++) nArray.push(array[i]);return nArray;}; Array.prototype.each=function(func){for(var i=0,l=this.length;i<l;i++) {func(this[i],i);};}; var getElementsByClassName=function(cn){ var hasClass=function(w,Name){ var hasClass = false; w.className.split(' ').each(function(s){ if (s == Name) hasClass = true; }); return hasClass; }; var elems =document.getElementsByTagName("*")||document.all; var elemList = []; $c(elems).each(function(e){ if(hasClass(e,cn)){elemList.push(e);} }) return $c(elemList); }; /*-----------------封装结束---------------------*/ window.onload=function(){ GetTag("input")[0].onclick=function(){alert("id为test的div内容是:\n"+GetId("test").innerHTML)} GetTag("input")[1].onclick=function(){alert("body里共有"+GetTag("li").length+"个li")} GetTag("input")[2].onclick=function(){alert("DIV里共有"+GetChildTag(GetId("test"),"li").length+"个li")} GetTag("input")[3].onclick=function(){alert("className为test2的内容是:\n"+GetClass("test2")[0].innerHTML+"\n"+GetClass("test2")[1].innerHTML)} } </script> </head> <body> <div id="test" title="这是id=test的div"> <ul title="div内第一个ul"> <li>ccontent1</li> <li>ccontent2</li> <li>ccontent3</li> <li>ccontent4</li> </ul> <ul class="test2" title="div内第二个ul,class=test2"> <li>bcontent1</li> <li>bcontent2</li> <li>bcontent3</li> </ul> </div> <ul class="test2" title="div外的ul,class=test2"> <li>content1</li> <li>content2</li> </ul> <input type="button" value="通过id获取" /> <input type="button" value="通过tag获取" /> <input type="button" value="通过id内tag获取" /> <input type="button" value="通过className获取" /> </body> </html></font> <a href="http://js.aiyiweb.com/">欢迎访问爱易网网页特效代码站,js.aiyiweb.com</a>
上一篇:狡猾的按钮特效
下一篇:关于减速运动效果
免责声明:
本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
相关资料
更多>
赴美开店,阿里11Main准备好了吗?
高德百度地图免费背后:李彦宏暗斗马云周鸿祎
猎豹移动上市押海外市场 与小米有合作空间
继续涨:微博IPO第二交易日 收盘大涨11.71%
搜狐与奇虎360或结盟对抗BAT
中方抗议美方限购IT设备 紧张关系加剧
Twitter收购印度手机营销公司ZipDial
杨元庆去年总薪酬1.33亿元
阿里马云:我觉得互联网还有十年可以做
推荐阅读
更多>
iPhone5S组件曝光 印证杀手级功能存在
逆转猜想:如果阿里成为雅虎大股东会怎样?
虚拟运营商们更像三大运营商的“二道贩子”
虚拟运营市场躁动:山西煤老板兴味浓重
Twitter收购印度手机营销公司ZipDial
从百度世界大会看大数据
微软很“捉急”:补贴Win8 重加末尾按钮
揭秘:阿里巴巴“无人认领”的三成股权都归谁
微软为避免代理权争夺 与大股东达成和解协议
三问刘强东:京东为何近来火气这么大?
Facebook财报前瞻:投资者仍信心不足
奇虎360证明了“惟平台化才能生存”是谬论,中国互联网不能少了周鸿祎
首个释放出搅局房地产信号的互联网公司不是小米而是58同城
华为、小米和联想在中国手机市场上演“三国杀”
中国邮政与阿里合作:邮政网点可做网购自提点
摩托罗拉中国区将再裁员 助力公司变身
史玉柱谈创业:5大建议 失败的教训最真实
特斯拉将获上海免费牌照 充电桩面临双重标准
国美苏宁线上首度正面PK 京东列席4月电商战
评论:阿里为什么不试着收购一家香港媒体呢