| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1479 人关注过本帖
标题:checkbox动态级联问题
只看楼主 加入收藏
zfxheb123
Rank: 1
来 自:山东济宁
等 级:新手上路
帖 子:23
专家分:0
注 册:2008-4-30
结帖率:100%
收藏
 问题点数:0 回复次数:2 
checkbox动态级联问题
jsp页面-------------------
<html>
    <head>
        <script type="text/javascript" src="js/json2.js"></script>
        <script type="text/javascript" src="js/types.js" ></script>
    </head>
    <body>
        <form action="softbrandtype.jsp">
            品牌:
            <c:forEach var="brand" items="${list}">
                <input type="checkbox" name="b" value="${brand.id}"
                    onclick="getTypesById(this.value)">${brand.name}</input>
            </c:forEach>
            <br>
            <div id="divid"></div>
            操作系统:
            <input type="checkbox" name="s">
            Android
            </input>
            <input type="checkbox" name="s">
            Symbian
            </input>
            <input type="submit" value="提交"/>
        </form>
    </body>
</html>
-------------------------types.js....代码
var xmlHttp;
function createXMLHttpRequest(){
    if(window.XMLHttpRequest){
        xmlHttp = new XMLHttpRequest();
    }else if(window.ActiveXObject){
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
}
function getTypesById(value){
    createXMLHttpRequest();
    var url = "servlet/FindTypesServlet";
    xmlHttp.open("post",url,true);
    xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    alter("=========");
    xmlHttp.onreadystatechange = function(){
        if(xmlHttp.readyState==4 && xmlHttp.status==200){
            response.setContentType("text/xml")
            var text = xmlHttp.responseText; //字符串 [xml文档的内容]
            var doc = xmlHttp.responseXML; //object js对象
            var types = doc.getElementsByTagName("types");
            var innerHTML = "<table width=500 border=1><tr><td>ID</td><td>机型</td><td>Pid</td><td>Pic</td></tr>";
            for(var i=0;i<types.length;i++){
                var t = types.item(i);
                var id = t.getAttribute("id");
                var name = t.getElementsByTagName("name")[0].firstChild.nodeValue;
                var pid = pid.getElementsByTagName("pid")[0].firstChild.nodeValue;
                var pic = student.getElementsByTagName("pic")[0].firstChild.nodeValue;
                innerHTML += "<tr><td>"+id+"</td><td>"+name+"</td><td>"+pid+"</td><td>"+pic+"</td>";
            }
            innerHTML += "</table>";
            document.getElementById("divid").innerHTML = innerHTML;
        }
    };
    xmlHttp.send("value="+value);
}
----------------Servlet代码

        response.setContentType("text/xml");
        PrintWriter out = response.getWriter();
        String[] str  = request.getParameterValues("value");
        BrandTypesDao dao = new BrandTypesDao();
        for(int i=0;i<str.length;i++){
            int id = Integer.parseInt(str[i]);
            List<Types> list = dao.selectTypesByPid(id);
            Document doc = DocumentHelper.createDocument();
            Element root = doc.addElement("list");
            for(Types t:list){
                Element types = root.addElement("types");
                types.addAttribute("id",t.getId()+"");
                Element name = types.addElement("name");
                name.setText(t.getName());
                Element pid = types.addElement("pid");
                types.setText(t.getPid()+"");
                Element pic = types.addElement("pic");
                types.setText(t.getPic());
            }
            
            out.print(doc.asXML());  //String text xml
            out.flush();
            out.close();

那位高手可以帮小妹看看





搜索更多相关主题的帖子: javascript 
2011-04-13 10:11
zfxheb123
Rank: 1
来 自:山东济宁
等 级:新手上路
帖 子:23
专家分:0
注 册:2008-4-30
收藏
得分:0 
等待中 做了好长时间效果老是出不来了
2011-04-13 10:13
天上的星星
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2011-6-18
收藏
得分:0 
小弟自己做了一个,挺简单,代码挺少,感觉非常好用,源码给你,好用的话顶一下!
级联.rar (283.95 KB)
程序代码:
下边是核心代码
function city(str)
{
var xmlhttp;
//document.getElementById("province").removeChild("option");
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 obj=document.getElementById("city");
    obj.options.length=1;
    var strings=xmlhttp.responseText;
    one=strings.split("|");
    two=one[0].split(",");
    three=one[1].split(",");
    document.getElementById("test").value=str;
    //strs=document.getElementById("province").value;
   
    var select1=document.getElementById("city");
   
    for(var i=1;i<two.length;i++){
        var opt=new Option(two[i],three[i]);
        select1.options.add(opt,i+1);

    }
    }
  }
var keys=document.getElementById("province").value;
xmlhttp.open("GET","content.asp?keys="+str,true);
xmlhttp.send();
document.getElementById("test1").value=document.getElementById("province").value;
}
function myvalue(){
document.getElementById("test2").value=document.getElementById("city").value;   
}
2011-06-18 12:07
快速回复:checkbox动态级联问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.040552 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved