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

js能不能实现这样的功能???
IE关闭的时候,如果页面上的数据没有提交就提示
alert( '没有提交数据,确认要关闭吗? ');

能不能实现这样的功能?

------解决方案--------------------
window.onbeforeunload = function()
{
if (判断)
alert( '没有提交数据,确认要关闭吗? ');
}
------解决方案--------------------
自己调一下


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN ">
<html>
<head>
<title> New Document </title>
<meta name= "Generator " content= "EditPlus ">
<meta name= "Author " content= " ">
<meta name= "Keywords " content= " ">
<meta name= "Description " content= " ">
<script language= "JavaScript1.2 ">
<!--
issubmit = false;
test = function ()
{
//document.form[0].submit();
issubmit = true;
return false;
}
test1 = function ()
{
alert( '你没有提交数据! ');
return '你没有提交数据! ';
}
//-->
</script>

</head>

<body onbeforeunload= " return test1(); ">
<script language=vbscript>
function checkfeed()
i1=quest.qname.value
i2=quest.qemail.value
i3=quest.question.value
if i2 = " " then
msgbox "请填写您电话! "
quest.qemail.focus
elseif i3 = " " then
quest.question.focus
elseif len(i3)> 300 then
msgbox "对不起,留言内容不能超过300个字! "
quest.question.focus
end if
end function
</script>

<form name= "quest " method= "post " action= "Message_pass.asp ">
<tr>
<td width= "76 " align= "center " bgcolor= "B9E0F7 "> 您的姓名: </td>
<td width= "419 " bgcolor= "B9E0F7 ">
<input name= "qname " type= "text " class= "name " id= "qname " size= "25 " maxlength= "10 "> </td>
<p>
</tr>
<tr>
<td align= "center " bgcolor= "B9E0F7 "> 您的电话: </td>
<td bgcolor= "B9E0F7 ">
<input name= "qemail " type= "text " class= "qemail " id= "qemail " size= "25 " maxlength= "20 "> </td>
</tr>

<tr>
<td align= "center " bgcolor= "B9E0F7 " valign= "top "> </p>
<p> 请写内容: </td>
<td bgcolor= "B9E0F7 " width= "419 "> <textarea name= "question " cols= "50 " rows= "10 " class= "nr " id= "question ">
</textarea> </td>
</tr>
<tr>
<td colspan= "2 " align= "center " bgcolor= "B9E0F7 ">
<input name= "ddd " type= "button " class= "pass " onClick= "return test(); " value= "提 交 "> </td>
</tr>
</p>
</form>
</body>
</html>

------解决方案--------------------
onSubmit 的时候,作一个标记;
onBeforeUnload 的时候,根据这个标记来决定是否提示。