最簡單從<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>
在你提交的時候,如果你用戶名或者密碼填寫的是空那麼就會彈出用戶名不能爲空或者密碼不能爲空。當然也能來驗證其他的,郵箱啊,地址格式等等。