日期:2014-05-16  浏览次数:20335 次

js-useful-1

<%@ page language="java" contentType="text/html; charset=GB18030"
??? pageEncoding="GB18030"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>添加普通验证</title>
<script type="text/javascript">
?function checkSubmit(){
??var name = ?document.getElementById("name").value;
??if(""==name){
???alert("姓名不能为空");
???return false;
??}

??var code = document.getElementById("code").value;
??var regu =/^[A-Z]{2}$/;
??var re = new RegExp(regu);
??if(re.test(code)){
??}else{
???alert("请输入为2位大写字母的编号!");
???return false;
??}

??document.infoForm.action = "people_add2.action";??//是当前目录下的然后加上该地址,当前目录为http://192.168.1.75:8081/pages/;所以:http://192.168.1.75:8081/pages/people/people_add2.action
??//alert(document.infoForm.action);
??document.infoForm.action = "/people_add3.action";??//得到该服务目录加上该地址;即为http://192.168.1.75:8081/people_add3.action
??//alert(document.infoForm.action);
??
??if(confirm("确定提交吗?")){
???document.infoForm.submit();????????//可以这样提交到某个地址
??}
?}

?function checkSubmit2(){
??var name = ?document.getElementById("name2").value;
??if(""==name){
???alert("姓名不能为空");
???return false;
??}
??
??/****正则表达式开始****/
??var code = document.getElementById("code2").value;
??var regu =/^[A-Z]{2}$/;
??var re = new RegExp(regu);
??if(re.test(code)){
??}else{
???alert("请输入为2位大写字母的编号!");
???return false;
??}
??/****正则表达式结束****/

??document.infoForm2.action = "people_add2.action";??//是当前目录下的然后加上该地址,当前目录为http://192.168.1.75:8081/pages/;所以:http://192.168.1.75:8081/pages/people/people_add2.action
??//alert(document.infoForm.action);
??document.infoForm2.action = "/people_add3.action";??//得到该服务目录加上该地址;即为http://192.168.1.75:8081/people_add3.action
??//alert(document.infoForm.action);
??
??if(confirm("确定提交吗?")){
???document.infoForm2.submit();????????//可以这样提交到某个地址
??}
?}

?function showGrade(){
??var identity = ?document.getElementById("identity").value;
??if("2"==identity){
???document.getElementById("promptGrade").style.display ="block";
???document.getElementById("gradeTable").style.display ="block";
??}else{
???document.getElementById("promptGrade").style.display ="none";
???document.getElementById("gradeTable").style.display ="none";
??}
?}
?
?//跳转到某个地址.
?function toOtherPage(parm1,parm2){
??window.location="/people_query2.action?parm1="+parm1+"&parm2="+parm2;
?}

?//跳转到某个地址2.
?function toOtherPage2(parm1){
??window.navigate(parm1);
?}

?
</script>
</head>
<%
?String parm1 = "pram1aa";
%>
<body>
?<form action="" name="infoForm">
??<table>
???<tr>
????<td>姓名:</td>
????<td><input type="text"? id="name" name="name" value=""></td>
???</tr>
???
???<tr>
????<td>二位大写字母编号:</td>
????<td><input type="text"? id="code" name="code" value=""></td>
???</tr>
???
???<tr>
????<td>身份:</td>
????<td >
?????<select id="identity" name="identity" onchange="showGrade();">?
??????<option value="1">老师</option>
??????<option value="2">学生</option>
?????</select>
?????<div id="promptGrade" style="display: none">
??????<font style="color: red">还要选择选择年级</font>?
?????</div>
????</td>
????
???</tr>
???
???<tr>
???? <td colspan="2">
?????<table style="display: none" id="gradeTable">
??????<tr>
???????<td>年级:</td>
???????<td>
???????<select id="grade" n