dom学习基本代码第一部分
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>event deal</title>
<style type="text/css">
.leixing{color:red;}
</style>
<script type="text/javascript">
function bodyclick()
{
alert("first");
alert("second");
}
function f1()
{
alert(1);
}
function f2()
{
alert(2);
}
</script>
<script type="text/javascript">
function Confirm() {
if (confirm("是否继续")) {
alert("继续");
}
else {
alert("取消");
}
}
</script>
<script type="text/javascript">
var intervalId;
function DoSetInterval()
{//每隔一定时间执行一次代码
intervalId = setInterval("alert('hello')", 2000);//定时发生代码
//返回一个代码,可以通过clearinterval将他清除
}
setTimeout("alert('这个时间到了')", 5000);//一定时间后执行此代码,即定时执行一次
//clearTimeout();
//也可清除这个定时
</script>
<script type="text/javascript">//实现标题栏滚动
function scroll()
{
var title = document.title;
var top = title.charAt(0);
var less = title.substring(1, title.length );
document.title = less + top.toString();
}
var inter;
function startscroll()
{
inter = setInterval("scroll()",500);
}
</script> </head>
<body onload="btn.value = 'OK'" onbeforeunload="window.event.returnValue='文章会丢失'"><!--onmousedown="bodyclick()"-->
<p>点击我</p>
<input type="button" value="f1"onclick="document.ondblclick=f1"/><!--这里定义方式和下面写的方式是一样的效果-->
<input type="button" value="f2" onclick="document.ondblclick=f2" />
<input type="button"value="f3"onclick="f1()">
<input type="button" value="f4" onclick="f2()">
<br />
<input type="button"value="确认?"ondblclick="Confirm()"/>
<input type="button"value="navigate测试" id="btn"onclick="navigate('www.qq.com')"/>
<br />
<input type="button"value="开始" onclick="DoSetInterval()"/>
<input type="button"value="结束"onclick="clearInterval(intervalId)" />
<br />
<input type="button"value="开始滚动"onclick="startscroll()"/>
<input type="button" value="停止滚动" onclick="clearInterval(inter)" />
</body>
</html>