小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

在一個jsp頁面實現(xiàn)二級下拉框聯(lián)動,實時讀取數(shù)據(jù)庫數(shù)據(jù)(用javascript實現(xiàn))

 昵稱2807 2007-04-29
在一個jsp頁面實現(xiàn)二級下拉框聯(lián)動,實時讀取數(shù)據(jù)庫數(shù)據(jù)(用javascript實現(xiàn))

在一個jsp頁面實現(xiàn)二級下拉框聯(lián)動,實時讀取數(shù)據(jù)庫數(shù)據(jù),這個方法非常使用,只需要修改很小的地方就可以使用。設(shè)計的文件,serch.jsp,main.js,bytetostr.js,

先講一下main.js,這是javascript,其中注意修改jsp頁面名稱。

 

 function findObject(fName,initValue)...{
   var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
   xmlhttp.open("POST","searchmx.jsp?findObject="+fName+"&initValue="+initValue,false);//注意修改jsp頁面
   xmlhttp.send();
   document.getElementById(fName).innerHTML=bytes2BSTR(xmlhttp.responsebody); //bytes2BSTR函數(shù)在bytetostr.js中
 }

 其次為bytetostr.js,這是vbscript,這個不需要修改任何內(nèi)容,他的主要功能就是讀取數(shù)據(jù)轉(zhuǎn)換字符串用的。

 Function bytes2BSTR(vIn)
  dim i
  strReturn = ""
  For i = 1 To LenB(vIn)
  ThisCharCode = AscB(MidB(vIn,i,1))
  If ThisCharCode < &H80 Then
  strReturn = strReturn & Chr(ThisCharCode)
  Else
  NextCharCode = AscB(MidB(vIn,i+1,1))
  strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
  i = i + 1
  End If
  Next
  bytes2BSTR = strReturn
End Function
 

接下來就是serch.jsp頁面,只需要修改div中的id為你想要的名字,再將一開始的包更換一下,已經(jīng)sql語句改下就可以了,有不明白的可以參與討論

 

<%@ page contentType="text/html; charset=gb2312" language="java" import="com.sjth.zdsygl.vo.*,com.sjth.zdsygl.biz.*,java.util.*,com.sjth.zdsygl.jdbc.*, java.sql.ResultSet"%>//導(dǎo)入相應(yīng)的包
<%
//這部分代碼用于執(zhí)行查詢數(shù)據(jù)庫,返回字符串
  if (request.getParameter("findObject")!=null)...{
    if (request.getParameter("findObject").equals("hy_dm"))...{
      DBConnect conn = null;
      ResultSet rs = null;
      try...{                   
        out.print("<select name=‘hy_dm‘ onchange="javascript:findObject(‘hymx_dm‘,this.value)">");
        String sql = "select * from dm_hy group by left(hy_dm,7)";
        conn = new DBConnect();
        conn.setPstmt(sql);
        rs = conn.executeQuery(sql);
        while(rs.next())...{
          out.print("<option value=‘"+rs.getString("hy_dm")+"‘>"+rs.getString("hy_mc")+"</option>");
        }    
        out.print("</select>");
     }
     catch (Exception e)...{                   
     }
     finally...{
          try...{
            if (rs != null)
                rs.close();
            if (conn != null)
                conn.close();
          }
          catch (Exception e)...{
            e.printStackTrace();
          }
     }
   }
    if (request.getParameter("findObject").equals("hymx_dm"))...{
      DBConnect conn = null;
      ResultSet rs = null;
      try...{                   
        out.print("<select name=‘hymx_dm‘ >");
        String sql = null;
        if (request.getParameter("initValue").equals(""))...{
          sql = "select * from dm_hy";
        }
        else...{
          sql = "select * from dm_hy where hy_dm like ‘"+request.getParameter("initValue")+"%‘";
        }
        conn = new DBConnect();
        conn.setPstmt(sql);
        rs = conn.executeQuery(sql);
        while(rs.next())...{
          out.print("<option value=‘"+rs.getString("hy_dm")+"‘>"+rs.getString("hy_mc")+"</option>");
        }    
        out.print("</select>");
     }
     catch (Exception e)...{                   
     }
     finally...{
          try...{
            if (rs != null)
                rs.close();
            if (conn != null)
                conn.close();
          }
          catch (Exception e)...{
            e.printStackTrace();
          }
     }
   }
   return;
 }
%>
<html>
<head>
    <link href="CSS/table.css" type="text/css" rel="stylesheet">
    <script language=vbscript src="css/bytetostr.js"></script>
    <script language=javascript src="css/main.js"></script>//導(dǎo)入兩個js文件
</head>
<body>
      <div>所屬行業(yè):</div>
      <div id="hy_dm"></div> //用來顯示返回的字符串
      <div >所屬明細(xì)行業(yè):</div>
      <div id="hymx_dm"></div>//用來顯示返回的字符串
</body>
</html>
<script language="javascript">
       findObject("hy_dm","");
       findObject("hymx_dm","");//這兩條是頁面執(zhí)行是調(diào)用
</script>
 

歡迎大家討論

 

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1591585

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多