<script language="JavaScript">
function Popup(url, window_name, window_width, window_height) 
{ settings= 
"toolbar=no,location=no,directories=no,"+ 
"status=no,menubar=no,scrollbars=yes,"+ 
"resizable=yes,width="+window_width+",height="+window_height; NewWindow=window.open(url,window_name,settings); }function icon(theicon) { 
document.input.message.value += " "+theicon; 
document.input.message.focus(); 

</script><title>论坛</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- 
function CheckValue()//检查标题内容是否为空值
{
 var name=document.all.name.value;
  var re=/( )/gi
  name=name.replace(re,"")
  re=/\</gi
  name=name.replace(re,"&lt;")
  if(name==""||name.length<1)
  {
    alert("用户名不能为空");
    document.all.name.focus();
    return false;
  }
  document.all.name.value=name;
  TheText=document.all.email.value;
  var re=/( )/gi
  TheText=TheText.replace(re,"")
  if(TheText=="")
  {
        alert("内容不能为空");
    document.all.email.focus();
    return false;
  }  if (form1.mobile.value!="")
   {
    if(checkNumber1(form1.mobile.value)==false)
return false;
   } 
   if (form1.oicq.value!="")
   {
    if(checkNumber2(form1.oicq.value)==false)
return false;
   } 
  
  return true;
}function checkNumber1(TempS)
{
 for(Count=0;Count<TempS.length;Count++)
 {
    TempChar=TempS.substring(Count,Count+1);
    RefString="0123456789";
     if (RefString.indexOf(TempChar,0)==-1)
      {
       alert("手机号码有非法字符,请输入数字");
       form1.mobile.focus();
   return false;
      }
 }
}
function checkNumber2(TempS)
{
 for(Count=0;Count<TempS.length;Count++)
 {
    TempChar=TempS.substring(Count,Count+1);
    RefString="0123456789";
     if (RefString.indexOf(TempChar,0)==-1)
      {
       alert("OICQ有非法字符,请输入数字");
       form1.oicq.focus();
   return false;
      }
 }
}function Popup(url, window_name, window_width, window_height) 
{ settings= 
"toolbar=no,location=no,directories=no,"+ 
"status=no,menubar=no,scrollbars=yes,"+ 
"resizable=yes,width="+window_width+",height="+window_height; NewWindow=window.open(url,window_name,settings); }function icon(theicon) { 
document.input.message.value += " "+theicon; 
document.input.message.focus(); 

</script>还有一个问题,为什么该JSP文件的最后非要加个
<html><script language="JavaScript"></script></html>?有何用意

解决方案 »

  1.   

    jsp代码是服务端执行代码,即在服务端运行代码一般使用方法<%XXXXX%>
    javaScript是执行在客户端,即平时我们说的浏览器上script language="JavaScript"
    这里说的是语言版本是按javaScript执行
      

  2.   

    我知道你说的啊,我只是想问上面JS代码的含义,我没学过JS。 还有
    我的JSP文件整体结构是这样的
    <html> 
    <script language="JavaScript"> 
    ...
    </script>
    </html>
    <html> <script language="JavaScript"> </script> </html>
    留意着最后一行,是否多余?以及那个说过script为JS了。是多余的吧?
      

  3.   

    有哪个JS高手,能给我解释下上面几个function的作用啊?本人不胜感激啊。
      

  4.   

    第一个方法貌似是打开一个窗口啊!
    第二个方法是给 document.input.message.value  message文本框赋值下面的两个方法是检验手机号码是不是数字还有一个问题,为什么该JSP文件的最后非要加个
    <html> <script language="JavaScript"> </script> </html>?有何用意
    这个是多余的
      

  5.   

    第二个方法是给 document.input.message.value  message文本框赋值 这个有什么作用?请高手赐教
      

  6.   

    不输入信息你乍知道,信息不合法。功能好像也不全,就是一个文件框,你输入判断是不是手机号,和oicq号码是不是正确。
      

  7.   

    <script language="JavaScript">
    function Popup(url, window_name, window_width, window_height)//定义一些消息窗口的属性:如toolbar,location,status等
    { settings=
    "toolbar=no,location=no,=no,"+
    "status=no,menubar=no,scrollbars=yes,"+
    "=yes,width="+window_width+",height="+window_height;NewWindow=window.open(url,window_name,settings); }//建立个消息窗口function icon(theicon) {
    document.input.message.value += " "+theicon;
    document.input.message.focus();
    }
    </script><title>论坛 </title>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function CheckValue()//
    {
    var name=document.all.name.value;
      var re=/( )/gi //创建正则表达式定义一些字符
      name=name.replace(re,"")//将name中包含的上面定义的字符给替代成"",即删去
      re=/\ </gi
      name=name.replace(re,"&lt;")//同上
      if(name==""||name.length <1)
      {
        alert("用户名不能为空");
        document.all.name.focus();
        return false;
      }
      document.all.name.value=name;
      TheText=document.all.email.value;
      var re=/( )/gi
      TheText=TheText.replace(re,"")
      if(TheText=="")
      {
            alert("内容不能为空");
        document.all.email.focus();
        return false;
      }  if (form1.mobile.value!="")
      {
        if(checkNumber1(form1.mobile.value)==false)
    return false;
      }
      if (form1.oicq.value!="")
      {
        if(checkNumber2(form1.oicq.value)==false)
    return false;
      }
     
      return true;
    }function checkNumber1(TempS)//检查手机号码的有效性,Temps为传入的手机号码
    {
    for(Count=0;Count <TempS.length;Count++)//循环手机号码截取字符
    {
        TempChar=TempS.substring(Count,Count+1);//一段段截取,如输入手机号码为1324523,那么它依次截取的字符为1,3,2,4,5,2,3
        RefString="0123456789";//定义手机号码输入的格式只能为数字
        if (RefString.indexOf(TempChar,0)==-1)//将截取的字符进行格式校验,如出现非数字则运行if里面的代码
          {
          alert("手机号码有非法字符,请输入数字");
          form1.mobile.focus();  //输入重新聚焦
          return false;
          }
    }
    }
    function checkNumber2(TempS)//同上
    {
    for(Count=0;Count <TempS.length;Count++)
    {
        TempChar=TempS.substring(Count,Count+1);
        RefString="0123456789";
        if (RefString.indexOf(TempChar,0)==-1)
          {
          alert("OICQ有非法字符,请输入数字");
          form1.oicq.focus();
      return false;
          }
    }
    }
    function Popup(url, window_name, window_width, window_height)//同上
    { settings=
    "toolbar=no,location=no,directories=no,"+
    "status=no,menubar=no,scrollbars=yes,"+
    "resizable=yes,width="+window_width+",height="+window_height;NewWindow=window.open(url,window_name,settings); }function icon(theicon) {
    document.input.message.value += " "+theicon;
    document.input.message.focus();
    }
    </script>
    最后的一句是多余的;一个网页文件里面只能存在一个<html></html>组,多了不解析或者出错!