打印

[Java] 常用的JAVASCRIPT代码,跟大家共享

常用的JAVASCRIPT代码,跟大家共享

一、复选框的全选:
<script language="JavaScript">
function CheckAll(form)
  {
  for (var i=0;i<form.elements.length;i++)
    {
    var e = form.elements;
    if (e.name != 'chkall' )
       e.checked = form.chkall.checked;
    }
  }
</script>

全选 <input name="chkall" type="checkbox" id="chkall" value="on" onclick=CheckAll(this.form)>

二、表单的检查:
<form name="form1" method="post" action="" onSubmit="return checkdata()">
<script language="javascript">
<!--
function checkdata()
        {
                if (document.form1.email.value=="")
                        {
                                window.alert("请输入你的E-mail地址!");
                                return false;
                        }
                if (document.form1.password.value=="")
                        {
                                window.alert("请输入你的密码!");
                                return false;
                        }
                if (document.form1.password.length<5)
                        {
                                window.alert("你的密码必须大于4位!");
                                return false;
                        }
                if (document.form1.password.length>16)
                        {
                                window.alert("你的密码必须小于16位!");
                                return false;
                        }
                if (document.form1.confirmpassword.value=="")
                        {
                                window.alert("请输入你的确认密码!");
                                return false;
                        }
                if (document.form1.password.value!=document.form1.confirmpassword.value)
                        {
                                window.alert("两次输入的密码不一致!");
                                return false;
                        }
                if (document.form1.name.value=="")
                        {
                                window.alert("请输入你的姓名!");
                                return false;
                        }
                return true;
        }
//-->
</script>


<script language="JavaScript">
function checkdata()
        {
                if (document.form1.title.value=="")
                        {
                                window.alert("请输入标题!");
                                return false;
                        }
                if (document.form1.content.value=="")
                        {
                                window.alert("请输入正文内容!");
                                return false;
                        }
        }       
</script>
将以下代码添加至表单的form标签中:
onSubmit="return checkdata()"

三、对话框确认并网页重定向或返回:
<script language="javascript">
        alert("感谢你的点击!");
        self.location="*.asp"
</script>

<script language="javascript">
        alert("感谢你的点击!");
        history.go(-1);
</script>

四、删除确认:
javascript:if(confirm('确定要删除吗?')) window.navigate('delete.asp?id=<%= rs("id") %>')
javascript:if(confirm('确定要删除吗?')) window.navigate('delete.jsp?id=<%= rs.getString("id") %>')
javascript:if(confirm('确定要删除吗?')) window.navigate('delete.aspx?id=<%# DataBinder.Eval(Container.DataItem,"id") %>')

五、返回上一页:    javascript:history.back()

六、按钮事件:
onclick="javascript:window.navigate('*.asp');"
onclick="history.back()"

七、跳转菜单:
<select name="showPage" onChange="javascript:window.location='rsnav.asp?showPage='+this.options[this.selectedIndex].value;">

<input name="Submit" type="button" onClick="MM_jumpMenuGo('menu1','parent',0)" value="查询">


<input name="Submit" type="button" onClick="javascript:window.open(menu1.options[this.selectedIndex].value);" value="查询">
window.open('url.aspx');

TOP

不错,谢谢楼主哦

TOP

正好最近要用这些东西

TOP

谢分享

TOP

都是一些基础知识.好理解.好应用.顶一个

TOP


感谢一直以来您对我们的支持!
当前时区 GMT+8, 现在时间是 2008-10-13 09:22 京ICP证060528 号

Designed By 17DST