提示:
if(confirm("XXXX"))
{//点“是”的时候 返回TRUE
window.open("XX");
}else
{//点“否”的时候 返回FALSE
window.open("XXX");
}
我的bug:
form提交前弹出对话框,请用户确认是否提交。点“是”则提交,点“否”则不提交。
在测试的时候,无论点“是”或“否”,页面都会提交。
经修改: <script type="text/javascript" language="javaScript">
function check(){
var a=document.forms[0].ss.value;
var b=document.forms[0].aa.value;
if(confirm("请确认您提交的数据:"+a+"年"+b+"人")){
document.forms[0].submit();
}else{
return false;
}
}
</script>
<form action="Input.jsp" method="post" οnsubmit="return flase">
年份: <select name="ss" >
<option value="2010">2010</option>
</select>
人数:<input type="text" name="aa">
<input type="button" value="确定" οnclick="javascript: check()">
</form>
总结:不可将提交按钮的type设为submit。
form onsubmit 验证不为空
<script type="text/javascript" language="javascript">
<!--
function IsEmpty(aTextField) {
if ((aTextField.value.length==0) || (aTextField.value==null))
{
return true;
}else
{ return false; }
}
function check(){
var mm=/^/d+$/;
var theForm = document.forms[0];
if (!theForm) { theForm = document.Form[0];}
if(!mm.test(theForm.allNum.value))
{
alert('"人员总数" 只能输入数字!!!!');
theForm.allNum.focus();
return false;
}
if(IsEmpty(theForm.UserName))
{
alert('请输入用户名!');
theForm.username.focus();
return false;
}
return true;
}
</script>
<form action="Register_conf.jsp" method="post" οnsubmit="return check()">
<input type="button" name="return" οnclick="javascript:history.go(-1)" value=" 返 回 " />
<input type="submit" name="button" value="注 册 用 户" />
参考内容:
1,对话框:
提示对话框:alert('提示信息');
确认对话框:confirm('确定要删除吗?')
应用,例如一个超级链接中:<a href="url" target="_self" οnclick="return confirm('确定要删除吗?')">,当点击"是"时,跳转到连接的URL,点击"否"时,不执行跳转.
输入对话框:prompt('标题','默认文本'),返回输入的信息;
例子:
<script type="text/javascript" language="javascript">
x=prompt("请输入数字:",1);
switch(parseInt(x))
{
case 1:
case 2:
case 3:
document.write("winner!");
break;
default:
alert("don't give up!");
}
</script>
3,Javascript刷新页面的几种方法:
(1) history.go(0)
(2) location.reload()
(3) location=location
(4) location.assign(location)
(5) document.execCommand('Refresh')
(6) window.navigate(location)
(7) location.replace(location)
(8) document.URL=location.href
---------------------------------------------------------------------
4,自动刷新页面的方法:
(1).页面自动刷新:把如下代码加入<head>区域中
<meta http-equiv="refresh" content="20">
其中20指每隔20秒刷新一次页面.
(2).页面自动跳转:把如下代码加入<head>区域中
<meta http-equiv="refresh" content="20;url=http://www.wyxg.com">
其中20指隔20秒后跳转到http://www.wyxg.com页面
(3).页面自动刷新js版
<script language="JavaScript">
function myrefresh()
{
window.location.reload();
}
setTimeout('myrefresh()',1000); //指定1秒刷新一次
</script>
---------------------------------------------------------------------
5,JS刷新框架的脚本语句
//如何刷新包含该框架的页面用
<script language=JavaScript>
parent.location.reload();
</script>
//子窗口刷新父窗口
<script language=JavaScript>
self.opener.location.reload();
</script>
( 或 <a href="javascript:opener.location.reload()">刷新</a> )
//如何刷新另一个框架的页面用
<script language=JavaScript>
parent.另一FrameID.location.reload();
</script>
如果想关闭窗口时刷新或者想开窗时刷新的话,在<body>中调用以下语句即可。
<body οnlοad="opener.location.reload()"> 开窗时刷新
<body onUnload="opener.location.reload()"> 关闭时刷新
<script language="javascript">
window.opener.document.location.reload()
</script>
---------------------------------------------------------------------
6,定位网页中的不同资源获取本地网页的URL
location.href:URL全局的值
location.protocol:URL内的http和ftp协议部分的值
location.hostname:URL内的主机名部分的值
location.pathname:URL内的路径名称部分的值
location.port:URL内的端口号的值
location.host:主机名和端口号部分的值
---------------------------------------------------------------------
7,返回上一次打开的链接
javascript:history.go(-1);
---------------------------------------------------------------------
8,获得参数:
得到数组:mainKinds = request.getParameterValues("mainKind") ;
得到单数值:mainKind = request.getParameter("mainKind") ;