function fn_Login_validate(){
var userName =document.getElementById("logName");
var pwd =document.getElementById("logPwd"); 
if(userName.value.Trim()==""){
ymPrompt.errorInfo({message:'操作失败:请填写用户名!',height:'150',title:'登陆错误提示'});
return false;
}
if(pwd.value.Trim()==""){
ymPrompt.errorInfo({message:'操作失败:请填写密码!',height:'150',title:'登陆错误提示'});
return false
}else{
//这里不写 直接执行登陆action
}
} 以上js 运行的时候在IE 搜狗 360 都运行没有问题。但是今天在火狐上运行的时候。 不提示任何错误。也不弹出对话框 直接就提交表单了。一下是表单部分。各位帮忙看看那个错误了。。 谢谢了。<form action="" method="post" onsubmit="return fn_Login_validate();">
<table width="230" height="75" border="0" cellpadding="0"
cellspacing="0">
<tr>
<td width="51"
style="font-size:12px; font-weight:600; color:#8D96AA">
用户名:
</td>
<td width="80">
<input type="text" name="logName"
style="width:69px; height:18px; border:1px solid #8D96AA;color:#666666;font-size: 12px;" />
</td>
<td width="99" align="left">
<font style="font-size:12px; font-weight:600;color:#E48A37;">
<input type="checkbox" value="1" name="saveCookis"
style="background:#AEC991; width:13px; height:13px;color:#666666;font-size: 12px;" />
记住</font>
<a href="#" title="注册新用户"
style="font-size:12px; font-weight:600;color:#1165AF;cursor:hand;">注册</a>
</td>
</tr>
<tr>
<td style="font-size:12px; font-weight:600; color:#8D96AA">
密 &nbsp;码:
</td>
<td>
<input type="password" name="logPwd"
style="width:69px; height:18px; border:1px solid #8D96AA;" />
</td>
<td>
<input type="submit" value="登录"
style="background:#FFFFFF; border:1px solid #1165AF; height:18px;font-size:12px; font-weight:600;color:#1165AF; width:30px;cursor:hand;" />
<a href="#"
style="font-size:12px; font-weight:600;color:#1165AF;cursor:hand;"
title="忘记密码">忘记密码</a>
</td>
</tr>
<tr>
<td colspan="3" align="left"
style="font-size:12px; font-weight:600; color:#000000;">
</td>
</tr>
</table>
</form>

解决方案 »

  1.   

    <input type="text" name="logName" id="logName"
    <input type="password" name="logPwd" id="logPwd"
      

  2.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">兼容性……
      

  3.   

    FF是不能用getElementById("")获取name为xxx的元素的
    把input加上ID就可以了
    id=logName
      

  4.   

    <input type="text" name="logName" id="logName" />
    id 你没写 。ie真的没问题 ?
    else if(pwd.value.Trim()==""){
      

  5.   

    楼上都说的对,加上ID,IE可以通过 name="logName"使用document.getElementById("logName");得到,但是火狐必须加上ID
      

  6.   

    不是ID的问题,是两种浏览器DOM模型略有差异,搜狗和IE是同是核心,而ff不是。
    在FF中,要用window.document.getElementById,
      

  7.   

    要解决不同浏览器之间的兼容问题,最好用第三方库,如jQuery,
    var userName =document.getElementById("logName");
        var pwd =document.getElementById("logPwd"); 
    改成这样:
    var userName =$("#logName").text();
    var pwd =$("#logPwd").text();