<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>外汇喊单网</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<style type="text/css">
#nav{background-image:url(images/navM.gif);}
#nav div{
background-image:url(images/nav_S.gif);
float:left;
width:4px; 
height:34px; 
font-size:0px; 
margin:0px 4px; 
background-repeat:no-repeat; 
background-position:top; 
background-repeat:no-repeat;
}
a.nav{
display:block; float:left; padding-left:12px; font-weight:bold; color:#fff; height:34px; font-size:14px; text-decoration:none; cursor:pointer;
}
a.nav span{
display:block; float:left; padding-right:12px; font-weight:bold; height:24px; padding-top:10px;
}
a.nav:hover{
display:block; float:left; padding-left:12px; font-weight:bold; color:#fff; height:34px; font-size:14px; background-image:url(images/nav_Over_L.gif); background-position:left center; background-repeat:no-repeat; text-decoration:none;
}
a.nav:hover span{
display:block; float:left; padding-right:12px; font-weight:bold; height:24px; padding-top:10px;background-image:url(images/nav_Over_R.gif); background-position:right center; background-repeat:no-repeat;
}
#curTab{
display:block; float:left; padding-left:12px; font-weight:bold; color:#f00; height:34px; font-size:14px;background-image:url(images/nav_On_L.gif); background-position:left center; background-repeat:no-repeat;
}
#curTab span{
display:block; float:left; padding-right:12px; font-weight:bold;height:24px; padding-top:10px;background-image:url(images/nav_On_R.gif);background-position:right center; background-repeat:no-repeat;
}
input {border:1px solid #c00;}
input {star : expression(
onmouseover=function(){this.style.borderColor="#060"},
onmouseout=function(){this.style.borderColor="#c00"})}
</style>
<script language="javascript">
function $(objId){
return document.getElementById(objId);
}
function changeId(idName,obj){
$(idName).id="";
obj.id=idName;
obj.blur();
}
function strContains(str,sub){
return(str.indexOf(sub)!=-1);
}
function reg()
{
   document.getElementById("reg").style.left=(window.screen.width-400)/2;
   document.getElementById("log").style.visibility="hidden";
   document.getElementById("reg").style.visibility="visible";
}function log()
{
   document.getElementById("log").style.left=(window.screen.width-400)/2;
   document.getElementById("reg").style.visibility="hidden";
   document.getElementById("log").style.visibility="visible";
}
function dolog()
{
  var username=document.getElementById("username").value;
var password=document.getElementById("password").value;
if(username==''||password=='')
{
  window.alert("用户名和密码不能为空!");
}
else
{
var xmlhttp;
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
       xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
       xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
          var result=xmlhttp.responseText;
          result=result.replace(/^\s*|\s*$/,'');
          if(strContains(result,'no'))
          {
             window.alert('用户名或密码错误');
          }
          else
          {
             document.getElementById("welcome").innerHTML="欢迎你:"+username;
             document.getElementById("log").style.visibility="hidden";
          }
          document.getElementById("welcome").innerHTML=result;
     xmlhttp.open("GET","DBlog.jsp?username="+regusername+"&password="+password,true);
     xmlhttp.send();
}
}function checkusername()
{
  var regusername=document.getElementById("regusername").value;
  if(regusername=='')
  {
    window.alert("用户名不能空");
  }
  else
  {
     var xmlhttp;
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
       xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
       xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
         if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
          var result=xmlhttp.responseText;
          result=result.replace(/^\s*|\s*$/,'');
          if(strContains(result,'no'))
          {
             window.alert('用户名或密码错误');
          }
          else
          {
             document.getElementById("welcome").innerHTML="欢迎你:"+username;
             document.getElementById("log").style.visibility="hidden";
          }
          document.getElementById("welcome").innerHTML=result;
        }
      };
  }
}
</script>
<script language="javascript" type="text/javascript">
if(window.screen.width>800){document.write("<style type=\"text/css\">body{margin-left:"+(window.screen.width-800)/2+"px}</style>");}
</script>  </head>
  
  <body>
    <img width=800 align="absmiddle" src="selfimg/page_1.png"/><br />
<table width=800 border="0" align="left" cellpadding="0" cellspacing="0">
      <tr>
        <td width="3"><img src="images/navL.gif" width="3" height="34" /></td>
        <td id="nav">
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
<td>
<a href="#" id="curTab" class="nav" onclick="changeId('curTab',this)"><span>首页</span></a> <div></div>
<a href="#" class="nav" onclick="changeId('curTab',this)"><span>网站建设</span></a>
<div></div>
<a href="#" class="nav" onclick="changeId('curTab',this)"><span>软件开发</span></a>
<div></div>
<a href="#" class="nav" onclick="changeId('curTab',this)"><span>虚拟主机</span></a>
<div></div> <a href="#" class="nav" onclick="changeId('curTab',this)"><span>域名注册</span></a>
<div></div>
<a href="#" class="nav" onclick="changeId('curTab',this)"><span>企业信息化</span></a>
</td>
  </tr>
</table>
</td>
        <td width="3"><img src="images/navR.gif" width="3" height="34" /></td>      </tr>
</table>
<br />
<br />
<table>
<tr>
<td>
<table align="left" style="width:800;height:25;text-align :justify">
<tr>
 <td id="welcom" align="left" style='width:50%;font:8pt Arial'>
 <label id="welcome">欢迎你:游客</label>
 </td>
 <td id="login" align="right" style='width:50%;font:8pt serif'>
 <a href="javascript:void(0)" onclick="window.alert('fuck');">注册</a>   或者  <a href="javascript:void(0)" onclick="log()">登陆</a> 
 </td>
 </tr>
</table>
<br>
</td>
</tr>
<tr>
<td>
<table width="800" align="left" id="内容">
<tr>
<td width="150px" style='word-break:break-all'> 
dsaddsadsadsa
</td>
<td width="500px" style='word-break:break-all;' align="center">
dfgdfgffgghfghfghfghfghfghfhfhfhfghfghfg
</td>
<td width="150px" style='word-break:break-all'>
sfdsdfsdf
</td>
</tr>
</table>
</td>
</tr>
</table>
<div id="log" style="position:absolute; width:400px; height:150px; background-color:mintcream; z-index:1; visibility:hidden; left: 200px; top: 200px;" >
<table width="100%" height="100%">
<tr>
<td align="center" valign="middle" height=50px>
<label>用户名:</label>
<input type="text" id="username" style="width:150px">
</td>
</tr><tr>
<td align="center" valign="middle" height=50px>
<label>&nbsp;&nbsp;密码:</label>
<input type="password" id="password" style="width:150px">
</td>
</tr><tr>
<td align="left" valign="middle">
<table width=100% height=30px>
<tr>
<td width=50% align="center">
<input type="submit" value="确定" style="width:100px;background-color:transparent" onclick='dolog()'>
</td>
<td width=50% align="center">
<input type="button" value="取消" style="width:100px;background-color:transparent" onclick='document.getElementById("log").style.visibility="hidden";'>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<div id="reg" style="position:absolute; width:400px; height:300px;background-color:mintcream; z-index:2; visibility:hidden; left: 200px; top: 250px" >
<table width="100%">
<tr>
<td align="center" valign="middle" height=50px>
<label>&nbsp;&nbsp;用户名:</label>
<input type="text" id="regusername" style="width:150px" onblur="checkusername()">
</td>
</tr><tr>
<td align="center" valign="middle" height=50px>
<label>&nbsp;&nbsp;&nbsp;&nbsp;密码:</label>
<input type="password" id="regpassword" style="width:150px">
</td>
</tr><tr>
<td align="center" valign="middle" height=50px>
<label>重复密码:</label>
<input type="password" id="repeatpassword" style="width:150px">
</td>
</tr><tr>
<td align="center" valign="middle" height=50px>
<label>电子邮箱:</label>
<input type="text" id="regemail" style="width:150px">
</td>
</tr><tr>
<td align="left" valign="middle">
<table width=100% height=30px>
<tr>
<td width=50% align="center">
<input type="submit" value="确定" style="width:100px;background-color:transparent" onclick=''>
</td>
<td width=50% align="center">
<input type="button" value="取消" style="width:100px;background-color:transparent" onclick="document.getElementById('reg').style.visibility='hidden';">
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
  </body>
</html>点击注册按钮的时候javascript语句执行,但是后面登陆的时候如果换成javascript方法就不执行。我到底哪错了。

解决方案 »

  1.   

    缺少一个}<script language="javascript">
    function $(objId){
    return document.getElementById(objId);
    }
    function changeId(idName,obj){
    $(idName).id="";
    obj.id=idName;
    obj.blur();
    }
    function strContains(str,sub){
    return(str.indexOf(sub)!=-1);
    }
    function reg()
    {
      document.getElementById("reg").style.left=(window.screen.width-400)/2;
      document.getElementById("log").style.visibility="hidden";
      document.getElementById("reg").style.visibility="visible";
    }function log()
    {
      document.getElementById("log").style.left=(window.screen.width-400)/2;
      document.getElementById("reg").style.visibility="hidden";
      document.getElementById("log").style.visibility="visible";
    }
    function dolog()
    {
      var username=document.getElementById("username").value;
    var password=document.getElementById("password").value;
    if(username==''||password=='')
    {
    window.alert("用户名和密码不能为空!");
    }
    else
    {
    var xmlhttp;
      if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
      else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
      {
      var result=xmlhttp.responseText;
      result=result.replace(/^\s*|\s*$/,'');
      if(strContains(result,'no'))
      {
      window.alert('用户名或密码错误');
      }
      else
      {
      document.getElementById("welcome").innerHTML="欢迎你:"+username;
      document.getElementById("log").style.visibility="hidden";
      }
      document.getElementById("welcome").innerHTML=result;
      xmlhttp.open("GET","DBlog.jsp?username="+regusername+"&password="+password,true);
      xmlhttp.send();
    }
    }
    } //这里加个}function checkusername()
    {
      var regusername=document.getElementById("regusername").value;
      if(regusername=='')
      {
      window.alert("用户名不能空");
      }
      else
      {
      var xmlhttp;
      if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
      else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
      {
      var result=xmlhttp.responseText;
      result=result.replace(/^\s*|\s*$/,'');
      if(strContains(result,'no'))
      {
      window.alert('用户名或密码错误');
      }
      else
      {
      document.getElementById("welcome").innerHTML="欢迎你:"+username;
      document.getElementById("log").style.visibility="hidden";
      }
      document.getElementById("welcome").innerHTML=result;
      }
      };
      }
    }
    </script>
      

  2.   

    缺少一个}<script language="javascript">
    function $(objId){
    return document.getElementById(objId);
    }
    function changeId(idName,obj){
    $(idName).id="";
    obj.id=idName;
    obj.blur();
    }
    function strContains(str,sub){
    return(str.indexOf(sub)!=-1);
    }
    function reg()
    {
      document.getElementById("reg").style.left=(window.screen.width-400)/2;
      document.getElementById("log").style.visibility="hidden";
      document.getElementById("reg").style.visibility="visible";
    }function log()
    {
      document.getElementById("log").style.left=(window.screen.width-400)/2;
      document.getElementById("reg").style.visibility="hidden";
      document.getElementById("log").style.visibility="visible";
    }
    function dolog()
    {
      var username=document.getElementById("username").value;
    var password=document.getElementById("password").value;
    if(username==''||password=='')
    {
    window.alert("用户名和密码不能为空!");
    }
    else
    {
    var xmlhttp;
      if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
      else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
      {
      var result=xmlhttp.responseText;
      result=result.replace(/^\s*|\s*$/,'');
      if(strContains(result,'no'))
      {
      window.alert('用户名或密码错误');
      }
      else
      {
      document.getElementById("welcome").innerHTML="欢迎你:"+username;
      document.getElementById("log").style.visibility="hidden";
      }
      document.getElementById("welcome").innerHTML=result;
      xmlhttp.open("GET","DBlog.jsp?username="+regusername+"&password="+password,true);
      xmlhttp.send();
    }
    }
    //这里加个}function checkusername()
    {
      var regusername=document.getElementById("regusername").value;
      if(regusername=='')
      {
      window.alert("用户名不能空");
      }
      else
      {
      var xmlhttp;
      if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
      else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
      {
      var result=xmlhttp.responseText;
      result=result.replace(/^\s*|\s*$/,'');
      if(strContains(result,'no'))
      {
      window.alert('用户名或密码错误');
      }
      else
      {
      document.getElementById("welcome").innerHTML="欢迎你:"+username;
      document.getElementById("log").style.visibility="hidden";
      }
      document.getElementById("welcome").innerHTML=result;
      }
      };
      }
    }
    </script>
      

  3.   

    我把javascript脚本写进JS文件,这个错误提示出来了,不过还是感谢大家。