<script>
function check(){
if(form1.textname.value==null){
alert("请输入信息");
}
else {//你想要执行的语句}
}
</scriptt>
<form name=form1>
<input type=text name=textname>
<input type=button value=提交 onclick=check()>
</form>

解决方案 »

  1.   

    <script>
    function check(){
    if(String(form1.textname.value).replace(/^[\s]+|[\s]+$/g,'') == ""){
    alert("请输入信息");
    }
    else {//你想要执行的语句}
    }
    </script>
    <form name=form1>
    <input type=text name=textname>
    <input type=button value=提交 onclick=check()>
    </form>
      

  2.   

    我习惯用VBSCRIPT来判断表单是不是为空,不允许为空格的,你可以试试
    <script language=vbscript>
    function checknull(form)
    if trim(form.txtvalue)="" then
    msgbox("不能不空!")
    checknull=false
    exit function
    end if
    if trim(form.txtvalue1)="" then
    msgbox("不能不空!")
    checknull=false
    exit function
    end if
    checknull=true
    end function
    </script>
    <form name=form1 onsubmit="return checknull(this)">
    <input type=text name=txtvalue>
    <input type=text name=txtvalue1>
    </form>
    够用的话一定要给我分呀:)
      

  3.   

    <script language=javascript>
    function check(form1)
    {
     if((form1.title.value=="") and (form1.content.value==""))
       { alert("请输入值"); 
         return false;
         }
      else
        return true;
    }
    </script>   
    <form name=form1 action="addnews_act.jsp" method="POST" ENCTYPE="multipart/form-data">
    标题:<input type="text"  name="title" size="20" maxlength="100">
    文件位置:<input type="file" name="content" size="20">
    <input type="submit" value="确 定" name="B1" onclick="return check();">以上语句有错,指出并改正者有分
      

  4.   

    if((form1.title.value=="") and (form1.content.value==""))改为if((form1.title.value=="") && (form1.content.value==""))
      

  5.   

    <input type="submit" value="确 定" name="B1" onclick="return check();">改为:<input type="submit" value="确 定" name="B1" onclick="return check(this.form);">