我要在同张页面上调用2次javascript里的判断语句,要怎么实现,我现在只能调用一次,第二次调用时就不会去判断了。a.jsp地点:<input type="text" name="zhongwen"><a href="b.jsp">选择</a>b.jsp<%@  page  contentType="text/html;charset=gb2312" %>        
<%@  page  import="java.sql.*" %> 
<%@  page  import="java.util.*" %>
<html>   
  <head>   
  <meta   http-equiv="Content-Type"   content="text/html;   charset=gb2312">   
  <title>made   by   meixx</title>   
  <script   language="javascript">   
  <!--   
  function   Add(ObjSource,ObjTarget){   
  for(var   i=0;i<ObjSource.length;i++){   
  if(ObjSource.options[i].selected){   
  var   opt=document.createElement("OPTION");   
  ObjTarget.add(opt);   
  opt.value=ObjSource.options[i].value;   
  opt.text=ObjSource.options[i].text;   
  ObjSource.options.removeChild(ObjSource.options[i--])   
  }   
  }   
  }   
  function   AddAll(ObjSource,ObjTarget){   
  SelectAll(ObjSource);   
  Add(ObjSource,ObjTarget);   
  }   
  function   SelectAll(ObjSource){   
  for(var   i=0;i<ObjSource.length;i++){   
  ObjSource.options[i].selected=true;   
  }   
  }   
    
  function   doSubmit(){   
  SelectAll(frmDisplay.dltTarget);   
 // frmDisplay.action="";//设置form   提交的action   
 // alert(frmDisplay.action);   
 //select.options[select.selectedIndex].value
  frmDisplay.submit();//取消注释即可,提交上去的options   
  }   
  //->   
  </script>   
  </head>   
    
  <body>   
  <table   width="435"   border="1"   style="border-collapse:collapse   "   bordercolor="#111111"   cellpadding="0"   cellspacing="0" height="274">   
      <tr>
      <%
          Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();      
          String  url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";    
          String  user="sa";    
          String  password="";    
          Connection  conn=  DriverManager.getConnection(url,user,password);        
          Statement  stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);        
          String  sql="select  *  from  jobs";        
          ResultSet  rs=stmt.executeQuery(sql); 
      %>    
          <td   width="193">   
  <select   name="dltSource"   size="10"   multiple   style="width:198   ; height:189">   
  <% 
    while(rs.next()){
  %>
    <option>
        <%=rs.getString(3)%>
    </option>
  <% } %>
</select>
  <%rs.close();        
  stmt.close();        
  conn.close();        
  %>   
  </td>   
          <td   width="43"   valign="middle">   
  <p   style="width:100%"   align="center"><input   type="button"   value="->"   onClick="Add(document.all.dltSource,frmDisplay.dltTarget)"   title="添加"></p>   
  <p   style="width:100%"   align="center"><input   type="button"   value="=>"   onClick="AddAll(document.all.dltSource,frmDisplay.dltTarget)"   title="添加全部"></p>   
  <p   style="width:100%"   align="center"><input   type="button"   value="<-"   onClick="Add(frmDisplay.dltTarget,document.all.dltSource)"   title="删除"></p>   
  <p   style="width:100%"   align="center"><input   type="button"   value="<="   onClick="AddAll(frmDisplay.dltTarget,document.all.dltSource)"   title="删除全部"></p>   
  </td>   
          <td   width="195">   
  <form   id="frmDisplay"   action="22.jsp"   method="post"   style="margin:0">   
  <select   name="dltTarget" size="10"  multiple   style="width:198   ; height:189"></select>   
  </form>  
  </td>   
      </tr>   
      <tr>   
          <td   align="right"><input   type="reset"   onClick="javascript:window.location.reload();"   value="重置"></td>   
          <td   align="center"></td>   
          <td   align="left"><input   type="button"   value="选定"   onClick="doSubmit()"></td>   
      </tr>    
  </table>   
    
  </body>   
  </html> 点 选定后,把选定的值返回到a.jsp的<input>里,要怎么实现,给个具体的例子
如果返回到a.jsp的值能用动态显示的话(也就是一个<input>里面显示一个值,多个值就要用多个<input>来显示),要怎么实现

解决方案 »

  1.   

    把業務處理寫在jsp裏不好吧
    寫個class響應是不是更好一些
      

  2.   

    还有一个问题,怎么判断b.jsp 右边的复选框为空时,弹出一个提示
      

  3.   

    我想用javascript + JSP实现,不想引入calss,而且JAVA不怎么会
      

  4.   

    …………
    老兄你的javascript太好了!
    偶只能说个大概,你凑合吧,有不对的地方改改……
    在a.jsp里面大概可以这样写:地点:
    <%
        request.setCharacterEncoding("gbk");
        String[] str = request.getParameterValues("dltTarget");
        for(int i = 0;i<str.length();i++) {
    %>
    <input type="text" name="zhongwen"+"<%=i%>" value="<%=str[i]%>"><a href="b.jsp">选择</a>
    <%
        }
    %>
      

  5.   

    至于判断复选框是否为空那个问题,就需要你用javascript了
      

  6.   

    to(neptune0229)
    判断为空这个问题,我按我的思路写了一个判断,不过整个事件都不能执行了
      

  7.   

    其实你的b.jsp和java类。。差不多
    写成class
    可以为后续开发带来便利
    至于判断可以试用javascript
      

  8.   

    你把判断的部分写在doSubmit()里面,写到最前面不就行了么?
      

  9.   

    我就是把判断语句写在doSubmit()的最前面的,不能执行
      

  10.   

    myvicy
    本来我也想要这么实现的,不错不知道怎么写,能给我个例子吗?
      

  11.   

    <html>
    <head>
    <SCRIPT language=JavaScript>
    var x0;
    var y0;
    var selectenable=0;function initChkBox(obj){
    var coll=document.forms["form1"].tags("input");
        for (i=0;i<coll.length;i++){
        if (coll.item(i).name.substr(0,2)=="ck") {
    var offsetTop = 0;
    var offsetLeft = 0;
    var objP = coll.item(i);
    while (objP.tagName!="BODY"&&objP){
    offsetTop += objP.offsetTop;
    offsetLeft += objP.offsetLeft;
    objP = objP.offsetParent;
    }
    coll.item(i).X=offsetLeft+10;
    coll.item(i).Y=offsetTop+10;
    //alert(coll.item(i).X+","+coll.item(i).Y+","+coll.item(i).offsetHeight);
    }
    }
    }function initselect() {
           if (window.event.srcElement.tagName=="BODY") {
           window.event.returnValue = true;
           return;
           }
       
            x0=document.body.scrollLeft+event.clientX;
        y0=document.body.scrollTop+event.clientY;
    selectarea.setCapture();
        selectenable=1;
    }
    function startselect() {
        if (selectenable==1) {
            selectarea.style.visibility='visible';

            if(document.body.scrollLeft+event.clientX-x0>0) {
        selectarea.style.left=x0;
        selectarea.style.width=document.body.scrollLeft+event.clientX-x0;
      }
            else{
        selectarea.style.left=document.body.scrollLeft+event.clientX;
        selectarea.style.width=x0-(document.body.scrollLeft+event.clientX);
       }
            if (document.body.scrollTop+event.clientY-y0>0) {
       selectarea.style.top=y0;
       selectarea.style.height=document.body.scrollTop+event.clientY-y0;
       }
           else{
       selectarea.style.top=document.body.scrollTop+event.clientY;
       selectarea.style.height=y0-(document.body.scrollTop+event.clientY);
       }
    }
        window.event.returnValue = true;
    }function endselect() {
    if (selectenable==0) return false;
        selectenable=0;
    selectarea.style.visibility='hidden';
    selectarea.releaseCapture();
    document.onmousemove=null;
    var coll=document.forms["form1"].tags("input");
        for (i=0;i<coll.length;i++){
        if (coll.item(i).name.substr(0,2)=="ck") {
    /* if (((coll.item(i).X>selectarea.offsetLeft)&&(coll.item(i).X<selectarea.offsetLeft+selectarea.offsetWidth))&&((coll.item(i).Y>selectarea.offsetTop)&&(coll.item(i).Y<selectarea.offsetTop+selectarea.offsetHeight))){
    coll.item(i).checked=!coll.item(i).checked;}
    */
    if (coll.item(i).X>selectarea.offsetLeft)
    if (coll.item(i).X<selectarea.offsetLeft+selectarea.offsetWidth) 
    if (coll.item(i).Y>selectarea.offsetTop)
    if (coll.item(i).Y<selectarea.offsetTop+selectarea.offsetHeight)
    coll.item(i).checked=!coll.item(i).checked
    }
    }
    selectarea.style.pixelHeight=0;
    selectarea.style.pixelWidth=0;
    }/*function hideselect() {
        //if (document.body.scrollLeft+event.clientX==x0 && document.body.scrollTop+event.clientY==y0 && event.srcElement!=selectarea)
        selectarea.style.visibility='hidden';
    }*/
    function checkAll(){
      document.form1.allsel.checked=false;
      var coll=document.forms["form1"].tags("input");
        for (i=0;i<coll.length;i++){
        if (coll.item(i).name.substr(0,2)=="ck") {
        coll.item(i).checked=false;
     }
    }
    }
    function change(v){
      var f = document.forms["form1"];
      for (i=0;i<f.elements.length;i++)
        if (f.elements[i].name.substr(0,2)=="ck") f.elements[i].checked = v;
    }
    </SCRIPT>
     
    <script language="JavaScript" type="text/JavaScript">
    <!--
    function MM_reloadPage(init) {  //reloads the window if Nav4 resized
      if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
        document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
      else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
    }
    MM_reloadPage(true);
    //-->
    </script>
    <title>您想要的-www.51windows.Net</title>
    </head>
    <body onmousedown="initselect()" onmousemove=startselect() onmouseup=endselect() onselectstart="return false;" onLoad=initChkBox()>
    <table width="100%" height="100%" cellpadding="0" cellspacing="0" bgcolor="efefef">
    <tr><td>
      <DIV id=selectarea style="border:1px dashed black;HEIGHT: 42px; LEFT: 0px; POSITION: absolute; TOP: 0px; VISIBILITY: hidden; WIDTH: 67px; Z-INDEX: 10"> 
        <img src="null" height="1" width="1"> </DIV>
      <div id="Layer1" style="position:absolute; left:256px; top:39px; width:203px; height:401px; z-index:1"> 
        <form name="form1" action="">
          <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#339999">
            <tr bgcolor="#FFFFFF"> 
              <td width="13%"><input type="checkbox" name="ck1" value="checkbox"></td>
              <td width="87%">&nbsp;</td>
            </tr>
            <tr bgcolor="#FFFFFF"> 
              <td><input type="checkbox" name="ck2" value="checkbox"></td>
              <td>&nbsp;</td>
            </tr>
            <tr bgcolor="#FFFFFF"> 
              <td><input type="checkbox" name="ck3" value="checkbox"></td>
              <td>&nbsp;</td>
            </tr>
            <tr bgcolor="#FFFFFF"> 
              <td><input type="checkbox" name="ck4" value="checkbox"></td>
              <td>&nbsp;</td>
            </tr>
            <tr bgcolor="#FFFFFF"> 
              <td><input type="checkbox" name="ck5" value="checkbox"></td>
              <td>&nbsp;</td>
            </tr>
            <tr bgcolor="#FFFFFF"> 
              <td><input type="checkbox" name="ck6" value="checkbox"></td>
              <td>&nbsp;</td>
            </tr>
            <tr bgcolor="#FFFFFF"> 
              <td><input type="checkbox" name="ck7" value="checkbox"></td>
              <td>&nbsp;</td>
            </tr>
            <tr bgcolor="#FFFFFF"> 
              <td><input type="checkbox" name="ck8" value="checkbox"></td>
              <td>&nbsp;</td>
            </tr>
            <tr bgcolor="#FFFFFF"> 
              <td><input type="checkbox" name="ck9" value="checkbox"></td>
              <td>&nbsp;</td>
            </tr>
            <tr bgcolor="#FFFFFF"> 
              <td><input type="checkbox" name="ck10" value="checkbox"></td>
              <td>&nbsp;</td>
            </tr>
            <tr bgcolor="#FFFFFF"> 
              <td><input type="checkbox" name="ck11" value="checkbox"></td>
              <td>&nbsp;</td>
            </tr>
            <tr bgcolor="#FFFFFF"> 
              <td><input type="checkbox" name="ck12" value="checkbox"></td>
              <td>&nbsp;</td>
            </tr>
            <tr bgcolor="#FFFFFF"> 
              <td><input type="checkbox" name="ck13" value="checkbox"></td>
              <td>&nbsp;</td>
            </tr>
            <tr bgcolor="#FFFFFF"> 
              <td><input type="checkbox" name="ck14" value="checkbox"></td>
              <td>&nbsp;</td>
            </tr>
            <tr bgcolor="#FFFFFF"> 
              <td><input type="checkbox" name="ck15" value="checkbox"></td>
              <td>&nbsp;</td>
            </tr>
            <tr bgcolor="#FFFFFF"> 
              <td><input type="checkbox" name="ck16" value="checkbox"></td>
              <td>&nbsp;</td>
            </tr>
            <tr bgcolor="#FFFFFF"> 
              <td><input type="checkbox" name="ck17" value="checkbox"></td>
              <td>&nbsp;</td>
            </tr>
            <tr bgcolor="#FFFFFF"> 
              <td><input type="checkbox" name="ck18" value="checkbox"></td>
              <td>&nbsp;</td>
            </tr>
            <tr bgcolor="#FFFFFF"> 
              <td><input type="checkbox" name="ck19" value="checkbox"></td>
              <td>&nbsp;</td>
            </tr>
            <tr bgcolor="#FFFFFF"> 
              <td><input type="checkbox" name="ck20" value="checkbox"></td>
              <td>&nbsp;</td>
            </tr>
            <tr bgcolor="#FFFFFF"> 
              <td><input type="checkbox" name="ck21" value="checkbox"></td>
              <td>&nbsp;</td>
            </tr>
          </table>
          <input type="checkbox" name="allsel" value="checkbox" onclick="change(this.checked)">
          <button onClick="checkAll()">清空</button>
        </form>
      </div>
    </td></tr>  
    </table>
    </body>
    </html>
      

  12.   

    我要在同张页面上调用2次javascript里的判断语句,要怎么实现,我现在只能调用一次,第二次调用时就不会去判断了。要怎么引用???
      

  13.   

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title></title>
    </head>
    <body>
    <SCRIPT LANGUAGE="JavaScript">
    function check(form) {
    var checkit = false
    for (var i=0;i<form.sel.length;i++) {
    if (form.sel[i].checked) {checkit=true;break}
    }
    if (checkit) {return true} else {alert("please select one");return false}
    }
    </SCRIPT>
    <form name="form1" onsubmit="return check(this)">
    <input name="sel" type="radio" value="selA">A
    <input name="sel" type="radio" value="selB">B
    <input name="sel" type="radio" value="selC">C
    <INPUT TYPE="submit" VALUE="submit">
    </form></body>
    </html>刚发现上边那个错了 这个是判断的
     
    这个是单选框 复选框一样的