最简单从<a>标签开始说
<script>
function t(){
alert('点击a标签')
}
</script>
<body>
<div><a href="#" οnclick="t();">a标签弹窗</a></div>
</body>
这就是最简单的,然后是点击div标签弹窗,点击变色,文本弹窗
<script type="text/javascript">
window.οnlοad=function(){
document.getElementById("test1").οnclick=function(){
alert("点击div");
};
document.getElementById("test2").οnclick=function(){
this.style.background='blue';
};
document.getElementById("test3").οnclick=function(){
alert("点击文本");
};
document.getElementById("testd").οnclick=function(){
};
}
</script>
<style type="text/css">
#test1{
width:100px;height:100px;background:red;
}
#test2{
width:100px;height:100px;background:red;margin-top:20px;
}
</style>
<body>
<div id="test1">点击弹窗
</div>
<div id="test2">点击变色
</div>
<div id="test3">文本弹窗
</div>
</body>
还有就是鼠标经过事件和鼠标离开事件
<script type="text/javascript">
function mOver(obj)
{
obj.innerHTML="经过过程中"
}
function mOut(obj)
{
obj.innerHTML="经过离开后"
}
</script>
<body>
<div οnmοuseοver="mOver(this)" οnmοuseοut="mOut(this)" style="background-color:green;width:120px;height:20px;padding:40px;color:#ffffff;">鼠标经过事件</div>
</body>
还有鼠标经过文本变色
<body>
<a href="javavoid()" οnmοuseοver="style.color='red'" οnmοuseοut="style.color='blue'">
鼠标经过文本变色
</body>
还有控制登录或者注册页面必填的文本不能为空,比如:
<form method="post" action="loginsucc.php" name="send" onSubmit="return Check()">
<p align="center">用户名:
<input type="text" name="user_name" size="20" />
</p>
<p align="center">密码:
<input type="password" name="user_pwd" size="20" />
</p>
<p align="center">
<input type="submit" value="提交"/>
<input type="reset" value="取消"/>
</p>
<script language="javascript">
function Check(){
if(document.send.user_name.value==""){
alert("用户名不能为空");
return false;
}
if(document.send.user_pwd.value==""){
alert("密码不能为空");
return false;
}
return true;
}
</script>
</from>
在你提交的时候,如果你用户名或者密码填写的是空那么就会弹出用户名不能为空或者密码不能为空。当然也能来验证其他的,邮箱啊,地址格式等等。