- 浏览: 459607 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (272)
- java基础 (59)
- struts (8)
- spring (8)
- 数据库 (8)
- java 网络编程 (29)
- hibernate (3)
- JavaScript (10)
- 日志管理 (2)
- jsp (4)
- servlet (7)
- xml (4)
- ajax (2)
- web service (4)
- 算法与数据结构 (13)
- java 反射机制 (11)
- java 泛型 (3)
- java I/O (8)
- java 线程 (12)
- JavaEE (6)
- java解惑 (33)
- 工具 (5)
- MyEclipse编程实践 (1)
- OSGI (2)
- 设计模式 (9)
- 正则表达式 (0)
- EJB (3)
- Ubuntu linux (6)
- Android (1)
- web前端 (2)
- 找工作 (1)
- SCA (1)
- maven (1)
- 缓存 (1)
- json (1)
- javamail (1)
- 工作笔记 (2)
最新评论
-
霜花似雪:
博主可以分享一下源码吗?
使用maven构建web项目实例 -
王庆波-行:
很好的demo!
memcache使用实例 -
surpassno:
大写的牛逼
java可视化显示内存使用情况 -
zhulin0504:
怎么访问NetEcho.html页面呀???
applet与servlet的网络通信 -
springdata:
java多线程实例demo源代码下载:http://www.z ...
java多线程例子
1,列表节点操作
2,子节点操作
3,网页上时间显示
4,通过标签名引用文档元素
window对象的history属性
history_demo_2.html
history_demo_3.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>brother child demo</title> <script type="text/javascript"> window.onload = function() { var ul = document.getElementById('parent'); /* hack for gecko */ for(var i = 0; i < ul.childNodes.length; i ++) { if(ul.childNodes[i].nodeType == 3) ul.childNodes[i].parentNode.removeChild(ul.childNodes[i]);//删除纯文本节点 } for(var i = 0; i < ul.childNodes.length; i ++) { ul.childNodes[i].onmouseover = function() // 定义当鼠标划过时需要执行的程序 { if(this.previousSibling) // this指针指向当前对象,这里指ul.childNodes[i] { this.previousSibling.style.backgroundColor = '#ff0'; //黄色 } if(this.nextSibling) { this.nextSibling.style.backgroundColor = '#ff0'; // } this.style.backgroundColor = '#f00'; //自身为红色 } ul.childNodes[i].onmouseout = function() // 定义当鼠标划离时需要执行的程序 { if(this.previousSibling) // this指针指向当前对象,这里指ul.childNodes[i] { this.previousSibling.style.backgroundColor = '#fff'; } if(this.nextSibling) { this.nextSibling.style.backgroundColor = '#fff'; } this.style.backgroundColor = '#fff'; } } } </script> </head> <body> <ul id="parent"> <li>child node</li> <li>child node</li> <li>child node</li> <li>child node</li> <li>child node</li> <li>child node</li> <li>child node</li> <li>child node</li> <li>child node</li> </ul> </body> </html>
2,子节点操作
<!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>child node demo</title> <script type="text/javascript"> window.onload=function(){ var ul=document.getElementById("parent"); ul.firstChild.style.backgroundColor='#FFF'; ul.lastChild.style.backgroundColor='#F00'; for(var i=1;i<ul.childNodes.length-1;i++){ ul.childNodes[i].style.backgroundColor='#eee'; if(ul.childNodes[i].nodeType==3)ul.childNodes[i].parentNode.removeChild(childNodes[i]); } } </script> </head> <body> <h1>parent</h1> <ul id="parent"> <li>firstChild</li> <li>childNode</li> <li>childNode</li> <li>childNode</li> <li>childNode</li> <li>childNode</li> <li>childNode</li> <li>childNode</li> <li>childNode</li> <li>lastChild</li> </ul> </body> </html>
3,网页上时间显示
<!DOCUTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional/EN" "http://www.w3.org/TR/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html;charset=gb2312" /> <title>网页自动更新日期</title> <script language="JavaScript"> function getTimeString(){ // var t = new Date(); var year = t.getFullYear(); var month = t.getMonth()+1; //month从0开始 var d = t.getDate(); var hour = t.getHours(); var minute = t.getMinutes(); var second = t.getSeconds(); var str = year+'-'+month+'-'+d+' '+hour+':'+minute+':'+second; return str; } function refresh(){ document.getElementById("time").innerHTML=getTimeString(); } window.onload=function(){ //每隔一秒执行一次refresh函数 setInterval(refresh,1000); } </script> </head> <body> <h1>自动更新时间,每隔1秒刷新一次</h1> <div id = "time"></div> </body> </html>
4,通过标签名引用文档元素
<!DOCUTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional/EN" "http://www.w3.org/TR/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html;charset=gb2312" /> <title>通过标签名引用节点</title> <script language="JavaScript"> function modifyLinkColor(){ // var links = document.body.getElementsByTagName("a"); for(var i =0 ;i<links.length;i++){ links[i].style.backgroundColor='#FF0'; } } </script> </head> <body> <a href ="http://www.sina.com">新浪网站</a> <a href ="http://www.sina.com">新浪网站</a> <a href ="http://www.sina.com">新浪网站</a> <input type = "button" id="btnEdit" value="modify links bgcolor" onclick ="modifyLinkColor ();" /> </body> </html>
window对象的history属性
<!DOCUTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional/EN" "http://www.w3.org/TR/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html;charset=gb2312" /> <title>window的history属性得到历史记录</title> <script language="JavaScript"> function historyBack(){ history.back(); } function historyForward(){ history.forward(); } function historyGo(){ var n =parseInt(document.getElementById("txtHistory").value); history.go(n); } </script> </head> <body> <h1>history_demo_1<h1> history_demo_1.html <a href="history_demo_2.html">history_demo_2</a> <input type ="text" id="txtHistory" /> <input type ="button" id="btnGo" value="History.go" onclick="historyGo();" /> <br/> <input type ="button" id="btnBack" value="History.back" onclick="historyBack();" /> <br/> <input type ="button" id="btnForward" value="History.forward" onclick="historyForward();" /> </body> </html>
history_demo_2.html
<!DOCUTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional/EN" "http://www.w3.org/TR/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html;charset=gb2312" /> <title>window的history属性得到历史记录</title> <script language="JavaScript"> function historyBack(){ history.back(); } function historyForward(){ history.forward(); } function historyGo(){ var n =parseInt(document.getElementById("txtHistory").value); history.go(n); } </script> </head> <body> <h1>history_demo_2<h1> <a href="history_demo_1.html">history_demo_1</a> <br/> <a href="history_demo_3.html">history_demo_3</a> <input type ="text" id="txtHistory" /> <input type ="button" id="btnGo" value="History.go" onclick="historyGo();" /> <br/> <input type ="button" id="btnBack" value="History.back" onclick="historyBack();" /> <br/> <input type ="button" id="btnForward" value="History.forward" onclick="historyForward();" /> </body> </html>
history_demo_3.html
<!DOCUTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional/EN" "http://www.w3.org/TR/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html;charset=gb2312" /> <title>window的history属性得到历史记录</title> <script language="JavaScript"> function historyBack(){ history.back(); } function historyForward(){ history.forward(); } function historyGo(){ var n =parseInt(document.getElementById("txtHistory").value); history.go(n); } </script> </head> <body> <h1>history_demo_3<h1> <a href="history_demo_1.html">history_demo_1</a> <a href="history_demo_2.html">history_demo_2</a> <input type ="text" id="txtHistory" /> <input type ="button" id="btnGo" value="History.go" onclick="historyGo();" /> <br/> <input type ="button" id="btnBack" value="History.back" onclick="historyBack();" /> <br/> <input type ="button" id="btnForward" value="History.forward" onclick="historyForward();" /> </body> </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>addEventListener demo</title> <style type="text/css"> #demo { width:300px; height:300px; border:1px solid black; margin:30px; } </style> <script type="text/javascript"> var div = document.getElementById('demo'); //在浏览器中没有效果?浏览器的问题? function init() //注册div的mouseover和mouseout事件处理程序 { div.addEventListener('mouseover',setBackgroundColor,false); div.addEventListener('mouseover',setBorderStyle,false); div.addEventListener('mouseout',removeBackgroundColor,false); div.addEventListener('mouseout',removeBorderStyle,false); } function setBackgroundColor() //设置div的背景色为红色 { document.getElementById('demo').style.backgroundColor = '#f00'; } function removeBackgroundColor() //设置div的背景色为白色 { document.getElementById('demo').style.backgroundColor = '#fff'; } function setBorderStyle() //设置div的边框粗细为10像素 { document.getElementById('demo').style.border = '10px solid black'; } function removeBorderStyle() //设置div的边框粗细为1像素 { document.getElementById('demo').style.border = '1px solid black'; } window.addEventListener('load',init,false); //在window的load事件被触发时执行init函数 </script> </head> <body> <h1>addEventListener demo</h1> <div id="demo"></div> </body> </html>
发表评论
-
JavaScript内置对象
2011-06-24 15:19 1006Array 数组 var myArray = new Arra ... -
JavaScript基本语法与内置函数
2011-06-24 10:34 1465JavaScript使用var进行变量声明,变量名长度是任意的 ... -
JavaScript的windows对象,document对象一些例子
2011-06-23 16:19 1537window对象的方法,resizeTo和moveTo< ... -
JavaScript dom操作一些例子
2010-11-28 08:34 1118dom节点操作 克隆节点 <!DOCTYPE html ... -
javascipt语法
2010-09-15 08:47 1128对象的定义 基本格式如下: Function Obje ... -
JavaScript正则表达式
2010-08-27 08:44 935正则表达式是对字符串的结构进行的形式化描述,非常简洁优美,而且 ... -
JavaScript数组
2010-08-26 20:47 962JavaScript的数组也是一个 ... -
JavaScript函数
2010-08-26 19:58 925在JavaScript中,函数本身与其他任何的内置对象在低位上 ... -
JavaScript对象与JSON
2010-08-26 18:56 961对象的声明有三种方式: Ø 通过new操作符作用域O ...
相关推荐
javascript经典例子 javascript经典例子
最新300个JavaScript小例 很多例子哦
javascript实用例子文件javascript实用例子文件javascript实用例子文件
相当好的javascript例子,共有320c例子
这里面用很多JavaScript实用例子,初学者可以好好看看 ,非常实用!
javaScript程序例子,JSP网页设计
JavaScript基础知识例子.zipJavaScript基础知识例子.zip
300个JavaScript小例子300个JavaScript小例子300个JavaScript小例子
这个是100个javascript小例子 各种效果 操作表单页面等小例子 很有用 项目中直接copy就可以用 同样学习javascript的更合适用这些来学习
javascript login 例子javascript login 例子
javaweb 注册小列子 ,javascript前段验证,
javascript的一些好用的例子javascript的一些好用的例子javascript的一些好用的例子
一些Javascript的例子程序,包括动态显示文字,变色文字,跑马灯,动态时钟,日期时间显示等。
javascript入门实用例子,是web工程,可以用eclipse直接导入,非常实用。
JavaScript 例子,学习JavaScript非常有用的例子
html5 canvas 例子. javascript写的一个游戏,用canvas 绘制移动的背景,键盘控制蝙蝠飞翔,蝙蝠碰到山洞游戏结束.
javascript多种经典例子
C++ Builder 调用JavaScript的例子
非常好的小例子,会给你的网站带来意想不到的效果
Web设计开发常用Javascript例子