| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1479 人关注过本帖
标题:checkbox动态级联问题
取消只看楼主 加入收藏
zfxheb123
Rank: 1
来 自:山东济宁
等 级:新手上路
帖 子:23
专家分:0
注 册:2008-4-30
结帖率:100%
收藏
 问题点数:0 回复次数:1 
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
快速回复:checkbox动态级联问题
数据加载中...
 
   



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

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