小弟今天遇到一个问题,用javascript在客户端判断form中的textarea的内容是否为空。
部分代码如下,但不知为什么不能运行,上网找了些资料试了下也不行。请各位高手帮忙看看。
谢谢了。
<html>
        <form   id=xx   name=xx   action= "xx "   onsubmit= "return   checkinput(); ">
        <textarea   name=xx   id=xx   cols=xx   > </textarea>
<html>
<script   type= "text/javascript ">
function   checkinput()
{
if   (document.all.formname.textareaname.value== " ")
      {
        window.alert( '不能输入空值 ');
        document.all.formname.textareaname.foucs();
        return   false;
      }
return   true;
}

解决方案 »

  1.   


    document.formName.textareaName.value=="") 
      

  2.   


    var nm=document.getElementById("控件ID");if(nm.value.length<=0)
    {
    alert("概要名称入力してください!");
            nm.focus();
            
    }
      

  3.   


    if(document.getElementById("xx").innerText == "")
    {
        alert("xx.value is ''");
    }
      

  4.   

    if(/^\s*$/.test(document.getElementById("xx").value))
    {
        //为空
    }
      

  5.   

    document.getElementById("xx").innerHTML == ""
      

  6.   

    document.formName.textareaName.value.length==0 为空.不等于0就不为空
      

  7.   

    document.formName.textareaName.innerText == "";