`
xhy0422
  • 浏览: 279297 次
社区版块
存档分类
最新评论

用ajax实现级联菜单

阅读更多


张盈盈 11:15:18
<script>
var xmlHttpRequest;
var type;
function init()
{
try
{
   if(window.XMLHttpRequest)
   {
    xmlHttpRequest = new XMLHttpRequest();
   }
   else if(window.ActiveXObject)
   {
    xmlHttpRequest = new ActiveXObject("Microsoft.XMLHttp");
   }
}
catch (e)
{
alert('the navigate is not support XMLHttpRequest')
}
}

function changeChapter()
{
    var chapterId = document.all.chapter.value;
    type="1";
    //alert(chapterId);
    if(chapterId == "")
    {
    var section = document.all.section;
    section.options.length=0;
    section.add(new Option("--请选择--",""));
    var kp = document.all.knowledgePoint;
    kp.options.length=0;
    kp.add(new Option("--请选择--",""));
    }
    else
{
var url="<c:url value='/insertParentmessage.do?action=ajax&chapterId='/>"+chapterId;
//document.searchForm.action="<c:url value=' lectClient.do?clientCode='/>"+clientCode;
url="<%=request.getContextPath()%>/insertParentmessage.do?action=ajax&chapterId="+chapterId;
//alert(url);
//alert(document.searchForm.action.value);
if(xmlHttpRequest)
{
  xmlHttpRequest.open("GET",url,true);
  //alert('open')
  xmlHttpRequest.onreadystatechange=getResponse;
  xmlHttpRequest.send(null);
}
}
//document.searchForm.submit();
}

function changeSection()
{
    var sectionId = document.all.section.value;
    //alert(sectionId);
    type="2";
    if(sectionId == "")
    {
    var kp = document.all.knowledgePoint;
    kp.options.length=0;
    kp.add(new Option("--请选择--",""));
    }
    else
{
var url="<c:url value='/insertParentmessage.do?action=ajax&sectionId='/>"+sectionId;
//document.searchForm.action="<c:url value=' lectClient.do?clientCode='/>"+clientCode;
url="<%=request.getContextPath()%>/insertParentmessage.do?action=ajax&sectionId="+sectionId;
//alert(url);
//alert(document.searchForm.action.value);
if(xmlHttpRequest)
{
  xmlHttpRequest.open("GET",url,true);
  //alert('open')
  xmlHttpRequest.onreadystatechange=getResponse;
  xmlHttpRequest.send(null);
}
}
//document.searchForm.submit();
}

function getResponse()
{
   //alert(xmlHttpRequest.readyState);
   if(xmlHttpRequest.readyState==4)
   {
       //alert('getResponse');
    if(xmlHttpRequest.status==200)
    {
         //alert('xml text : '+xmlHttpRequest.responseText);
      //alert('xml text xml : '+xmlHttpRequest.responseXML);
      generalList();
    }
    else
    {
     alert('error do not return correct info');
    }
   }
}

function generalList()
{
    //alert('in generalList');
    var xmlDoc = xmlHttpRequest.responseXML.documentElement;
//alert('getxmlDoc'+ xmlDoc.xml);
var xSel = xmlDoc.getElementsByTagName("select");
//alert(xSel);
var temp = null;
if(type == "1")
{
temp = document.all.section;
var kp = document.all.knowledgePoint;
    kp.options.length=0;
    kp.add(new Option("--请选择--",""));
}
else
temp = document.all.knowledgePoint;
temp.options.length=0;
temp.add(new Option("--请选择--",""));
for(var i=0;i<xSel.length;i++)
{
var xValue = xSel[i].childNodes[0].firstChild.nodeValue;
  //alert('xValue : '+ xValue);
  var xText = xSel[i].childNodes[1].firstChild.nodeValue;
  var option = new Option(xText,xValue);
  temp.add(option);
}
}
init();

function addAtt()
{
//alert("addAtt");
var attTD = document.all.att;
//alert(attTD);
var count = document.all.attCount.value;
//alert(count);
if(count*1 > 4)
{
alert("已经达到最大附件数目!");
return;
}
var input = document.createElement("input");
input.type="file";
input.name="attachment_" + count;

//attTD.innerHTML += "<input type=\"file\" name=\"attachment_" + count + "\"/>";
//attTD.innerHTML += "<br/>";

attTD.appendChild(input);
attTD.appendChild(document.createElement("br"));
input.focus();
document.all.attCount.value = count*1 + 1;
}
</script>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics