<script type="text/javascript" defer="defer">
checkFill(document.getElementById("gp"));
checkAction(document.getElementById("nil"));
</script>我想通过网页生成后动态插入两张表,两张表是不同的位置
现实情况是,后一个函数的操作会使前一个函数显示的内容消失,
两个函数执行顺序变换一下效果正好相反。这是什么原因?
并且要怎么实现我想要的效果呢?

解决方案 »

  1.   

    是不是你操作的是同一个标签
    比如两个表都是放在一个div里面的
    你通过document.getElementById("div").innerHTML="html"都显示到同一个DIV里面了
      

  2.   

    onreadystatechage对应的函数查看一下!
      

  3.   

    技术上肯定可以,但是第一步要把数据拆出来,即你传过来的数据一部分要放表格A,另一部分要放表格B,这个你要先规定好.
    然后说到的"现实情况是,后一个函数的操作会使前一个函数显示的内容消失"是否两个表格都被包在一个元素里?表格是直接 ("对象").innerHTML=表格 还是 ("对象").appendChild(表格对象) ?问题不要这么简洁,要让我们猜来猜去就不好了
      

  4.   

    先解释下,
    checkAction(document.getElementById("nil")) 就是通过java返回的 table 放在
        <p id="tbr"></p>标签,
    option 的onchange事件同样触发这个函数。checkFill(document.getElementById("gp"))是通过java设置
        <input name="wl" id="wl<%=rs("wl_id")%>" type="checkbox" value="<%=rs("wl_id")%>" onclick="checkAction(this)">
    selected 属性,也就是 checkbox的选取。以下是<body>部分:
    <p id="tbr"></p>
    <table>
    <tr><td colspan="3">用户组:<select id="gp" name="gp" onchange="checkFill(this)">
    <option name="gl" value="" selected="selected"></option>
    <%
    sqlstr="select * from gp_list order by gl_id"
    rs.open sqlstr,conn,1,1
    if not(rs.bof and rs.eof) then
    rs.movefirst
    do while not rs.eof
    response.write "<option name=""gl"" value=""" & rs("gl_id") & """ >" & rs("gl_name") & "</option>"
    rs.movenext
    loop
    end if
    rs.close
    %>
    </select></td></tr><tr><td>&nbsp;</td></tr>
    <%<input name="wl" id="wl<%=rs("wl_id")%>" type="checkbox" value="<%=rs("wl_id")%>" onclick="checkAction(this)"></
    sqlstr="select * from web_list order by wl_id"
    rs.open sqlstr,conn,1,1
    if not(rs.bof and rs.eof) then
    rs.movefirst
    do while not rs.eof
    %>
    <tr><td>td><td><%=rs("wl_name")%></td><td><%=rs("wl_dn")%></td></tr>
    <%
    rs.movenext
    loop
    end if
    call connclose
    %>
    </table>
    <input id="nil" type="hidden" value="">
    </body>checkAction函数部分:
    function checkAction(checkBox)
    {
    var groupId;
    var webId;
    var transStr;
    var now=new Date();
    var gpl=document.getElementById("gp");
    groupId=gpl.options[gpl.selectedIndex].value
    webId=checkBox.value;
    if(checkBox.checked==true){
    transStr="action=1&gid="+groupId+"&wid="+webId+"&t="+now.getTime();
    }
    else{
    transStr="action=2&gid="+groupId+"&wid="+webId+"&t="+now.getTime();
    }
    if(window.XMLHttpRequest){
    xmlHttp=new XMLHttpRequest();
    }
    else{
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlHttp.open("Get","rightc.asp?"+transStr,true);
    xmlHttp.setRequestHeader("Content-type","text/html");
    xmlHttp.send();
    xmlHttp.onreadystatechange=function(){
    if(xmlHttp.readyState==4 && xmlHttp.status==200){
    document.getElementById("tbr").innerHTML=xmlHttp.responseText;
    }
    }
    return 0;
    }checkFill 函数部分:
    function checkFill(checkBox)
    {
    var groupId;
    var transStr;
    var xmlElm;
    var now=new Date();
    xmlElm=0;
    groupId=checkBox.options[checkBox.selectedIndex].value
    transStr="action=3&gid="+groupId+"&t="+now.getTime();
    if(window.XMLHttpRequest){
    xmlHttp=new XMLHttpRequest();
    }
    else{
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlHttp.open("Get","rightf.asp?"+transStr,true);
    xmlHttp.setRequestHeader("Content-type","text/html");
    xmlHttp.send();
    xmlHttp.onreadystatechange=function(){
    if(xmlHttp.readyState==4 && xmlHttp.status==200){
    //返回值
    if(xmlHttp.responseText!=""){
    checkEmpty();
    var xmlStr=xmlHttp.responseText.split("-");
    for(xmlElm in xmlStr){
    document.getElementById("wl"+xmlStr[xmlElm]).checked=true;
    }
    }
    else{
    checkEmpty();
    }
    }
    }
    return 0;
    }function checkEmpty() //checkFill调用
    {
    var chkl=document.getElementsByName("wl")
    for(var x=0;x<chkl.length;x++){
    chkl[x].checked=false
    }
    return 0;
    }
      

  5.   

    checkAction中的xmlHttp全部换一个名字(如xmlHttp_2),不要和checkFill的重复。或者都用同步的方法获取xmlHttp.open("Get","rightc.asp?"+transStr,false);
      

  6.   

    果真是重名问题,当时懒了,没有一步步跟踪下,犯了个低级错误。
    slowhand:多谢。