关于javascript脚本比较常用的几个方法

来源:互联网 发布:snp数据下载 编辑:程序博客网 时间:2024/04/26 17:21

最简单从<a>标签开始说

<script>function t(){alert('点击a标签')}</script><body><div><a href="#" onclick="t();">a标签弹窗</a></div></body>
这就是最简单的,然后是点击div标签弹窗,点击变色,文本弹窗

<script type="text/javascript">window.onload=function(){document.getElementById("test1").onclick=function(){alert("点击div");};document.getElementById("test2").onclick=function(){this.style.background='blue';};document.getElementById("test3").onclick=function(){alert("点击文本");};document.getElementById("testd").onclick=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 onmouseover="mOver(this)" onmouseout="mOut(this)" style="background-color:green;width:120px;height:20px;padding:40px;color:#ffffff;">鼠标经过事件</div></body>
还有鼠标经过文本变色

<body><a href="javavoid()" onmouseover="style.color='red'" onmouseout="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>
在你提交的时候,如果你用户名或者密码填写的是空那么就会弹出用户名不能为空或者密码不能为空。当然也能来验证其他的,邮箱啊,地址格式等等。



0 0
原创粉丝点击