<script type="text/javascript" language="java">
function check(){
var tname=document.form1.titlename.value;
var fpath=document.form1.filepath.value;

if(tname.length==""){
alert("二级标题不能为空!");
tname.focus();    加入这句话跳出后面所有行,直接到ruturn true这行
return false;
}

if(fpath.length==""){
alert("文件地址不能为空!");
return false;
}
return true;
}
</script>为什么直接跳到return true这里呢,我是嵌入在jsp页面里的。

解决方案 »

  1.   

    tname.length=="" 直接用  tname==""吧,下面的也一样要么就tname.length==0
      

  2.   

    一样的,里面有个错误,tname.focus()这句错了,是值,但改过来还是有问题,只要加上focus这方法,光标不会回到焦点,没辙了。
      

  3.   

    通过使用document.getElementById()试试看
      

  4.   

    这个问题很简单
    function check(){
            var tname=document.getElementById('titlename');
            var fpath=document.getElementById('filepath');
            
            if(tname.value==""){
                alert("二级标题不能为空!");
                tname.focus();    加入这句话跳出后面所有行,直接到ruturn true这行
                return false;            
            }
            
            if(fpath.value==""){
                alert("文件地址不能为空!");
                return false;
            }
            return true;
        }只所以出问题,时因为不应该取它的值