这是代码:
<script language="javascript">
function Check(){
if(topicCheck() && contentCheck())
return true;
else 
return false;
}
function topicCheck(){
var topic=document.getElementById("topic").value;
if(topic!="")
return true;
else
alert("主题不能为空!");
}
function contentCheck(){
var content=document.getElementById("content").value;
if(content!="")
return true;
else
alert("内容不能为空!");
} </script>
<font color="white"><p>创建新帖</p>
<form action="creatTopicCl.php" method="POST" name="creatTopic" onsubmit="return Check();">
主题:<input type="text" name="topic" id="topic" size="40"  width="50" onchange="topicCheck();"><br><br>
内容:<textarea name="content" id="content" rows="10" cols="50" onchange="contentCheck();">
</textarea><br>
<input type="submit" name="submit" value="提交" class="sub">
<input type="reset" value="重填" class="sub">

解决方案 »

  1.   

    && 操作,前面true则向后执行,前面false,则停止,所以topicCheck() && contentCheck()中topicCheck为false,则contentCheck不会执行。
      

  2.   

    没问题呀检查总是一步一步来的
    你给 topic 赋值了,才会去检查 content
      

  3.   

    改成这样<script src="http://code.jquery.com/jquery-latest.js"></script>
    <script type="text/javascript">
    $(function(){
    $("#submit").click(function(){
    if($("#topic").val()==""){
    alert("主题为空");
    return false;
    }else if($("textarea").val()==""){
    alert("内容为空");
    return false;
    }else{
    return true;
    }
    });
    })
    </script>
     <font color="white"><p>创建新帖</p>
     <form action="creatTopicCl.php" method="POST" name="creatTopic" />
    主题:<input type="text" name="topic" id="topic" size="40"  width="50" /><br><br>
    内容:<textarea name="content" id="content" rows="10" cols="50"/></textarea><br>
     <input type="submit" id="submit" value="提交" class="sub"/>
     <input type="reset" value="重填" class="sub"/> 
    你那个原因出在var content=document.getElementById("content").value;
    试着获取textarea标签
    var content=document.getElementByTag("textarea").value;
    不知道是不是这么写,反正大概是这个意思
      

  4.   

    var content=document.getElementByTag("textarea").value;
    改成这样还是不行啊?不知道为什么?
      

  5.   

    chrom、ie
    你的代码不会出现浏览器兼容问题