日期:2014-05-19  浏览次数:20737 次

JSP 简单的一个问题
<form action="rec" method = "post">
姓名:<input type="text" name="username"> <br>
性别:<input type="radio" name="男">男
<input type="radio" name="sex" value="女">女<br>
年龄:<select name="age">
<option value="及冠之年"> 及冠之年</option>
<option value="而立之年"> 及冠之年</option>
</select>
<br>
兴趣爱好: <input type="checkbox" name="love" value="跳舞"> 跳舞
<input type="checkbox" name= "love" value="唱歌">唱歌
<input type="checkbox" name="love" value="旅游">旅游<br>

<input type ="submit" value="提交" >



现在 lz想加上一个籍贯 name="country" value值有“中国”“美国”等等
然后,省份有“广东”“湖南”等等, 城市有“广州”"佛山"“深圳”
lz 是这么想:只有选择了“中国”才会有“广东”选择项,只有选择了“广东”才会有“广州”等选项给你选择
刚学的JSP










------解决方案--------------------
这个是ajax做出来的,你在google上收省市联动,有例子的
------解决方案--------------------
一个联动菜单的小例子,通过类别查找子类别,楼主可以参考下。
JScript code

var xmlHttp;
    function createXMLHttp()
    {
        if(window.XMLHttpRequest)
        {
            xmlHttp=new XMLHttpRequest();
        }
        else
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    function findSubTypes(tid)
    {
        createXMLHttp();
        xmlHttp.open("POST","ProductServlet?status=findbytypes&tid="+tid);
        xmlHttp.onreadystatechange=findSubTypesCallBack;
        xmlHttp.send(null);
        
    }
    function findSubTypesCallBack()
    {
        if(xmlHttp.readyState==4&&xmlHttp.status==200)
        {
            var allSubTypes=xmlHttp.responseXML.getElementsByTagName("subtypes")[0].childNodes;
            var select=document.getElementById("subtypes");
            select.length=1;
            select.options[0].selected=true;
            for(var i=0;i<allSubTypes.length;i++)
            {
                var subtype=allSubTypes[i];
                var option=document.createElement("option");    
                var stid=subtype.getElementsByTagName("stid")[0].firstChild.nodeValue;
                var title=subtype.getElementsByTagName("title")[0].firstChild.nodeValue;                                                                  
                option.setAttribute("value",stid);
                option.appendChild(document.createTextNode(title));
                select.appendChild(option);                
            }            
        }
    }