<script>
function checkit(form)
{
var j=0;
var title1=document.form1.title.value;
var author1=document.form1.author.value;
var keyword1=document.form1.keyword.value;
var preview1=document.form1.preview.value;
for(i=0;i<form1.sort1.length;i++)
  if(form1.sort1[i].checked)
     {
 j++;
 }
if(j==0) {alert("请选择类别");return(false);}
else if(title1=="")alert("标题不能为空");
else if(author1=="")alert("来源不能为空");
else if(preview1=="")alert("源代码框不能为空,请点编辑源代码");
else
{
 form.target="_self";
 form.action="article_add.php?add=1";
 form.submit();
}}
</script>

解决方案 »

  1.   

    应该不会出现这种情况:<html>
    <head>
    <title>New Page 1</title>
    <script>
    function aa()
    {
      if(document.all.T1.value=="")
      {
         alert("不能为空");
         return;
      }
      else document.all.Frm1.submit();  
    }
    </script>
    </head>
    <body>
    <form method="POST" action="" name="Frm1">
      <p><input type="text" name="T1" size="20"><input type="text" name="T2" size="20"><input type="button" value="提交" name="B1" onclick="aa();"><input type="reset" value="全部重写" name="B2"></p>
    </form></body></html>
    注意不要把B1的类型设为“submit”,而应为"button"
      

  2.   

    还是不行呀,点alert弹出的确定后表单中的信息全没了,怎么回事呢?我修改后的代码如下:<script>
    function checkit()
    {
    var j=0;
    var title1=document.form1.title.value;
    var author1=document.form1.author.value;
    var keyword1=document.form1.keyword.value;
    var preview1=document.form1.preview.value;
    for(i=0;i<form1.sort1.length;i++)
      if(form1.sort1[i].checked)
         {
     j++;
     }
    if(j==0) {alert("请选择类别");return;}
    else if(title1==""){alert("标题不能为空");return;}
    else if(author1==""){alert("来源不能为空");return;}
    else if(preview1=="")alert("源代码框不能为空,请点编辑源代码");
    else
    {
     document.form1.submit();  
    }<input type="submit" name="Submit" value="提交表单" onClick="checkit()">
      

  3.   

    哦,问题解决了,原来将
    <input type="submit" name="Submit" value="提交表单" onClick="checkit()">
    改为:
    <input type="button" name="button1" value="提交表单" onClick="checkit()">
      

  4.   

    <html>
    <head>
    <title>New Page 1</title>
    <script>
    function aa()
    {
      if(document.all.T1.value=="")
      {
         alert("不能为空");
         history.back();   <--------------------我觉得这样也行,你试试看!
      }
      else document.all.Frm1.submit();  
    }
    </script>
    </head>
    <body>
    <form method="POST" action="" name="Frm1">
      <p><input type="text" name="T1" size="20"><input type="text" name="T2" size="20"><input type="button" value="提交" name="B1" onclick="aa();"><input type="reset" value="全部重写" name="B2"></p>
    </form></body></html>