removeChild引數不正確?

edited 十月 2013 in Javascript
就是我有一個表單
必須處理四階樹系遞迴的欄位輸入,由於項數並不一定
所以用javascript去即時產生欄位
問題在於寫入資料庫後再撈出來時也必須能夠即時進行表單欄位增刪改
可是出了一個查不出來的錯誤,"不正確的引數",我確定給予的父.子引數(元素)都沒有問題,可以對該元素做其他操作,就...removeChild(),一律出現"不正確的引數".....
這個問題發生在第四階,其他三階"完全正常",有沒有人提供點方向,這BUG花了六小時還打不死 Q.Q
code很長...我想幫助不大,php部份只選重點貼
php
<td class='form100r' style='vertical-align:bottom;'>本次計劃內容<br />
        <input type='button' class='buttones' value='新增計劃' onclick='add_plans(true,\"upd_plans\")'  />
        </td>
        <td class='form500'> 
        <div id='upd_plans'>";
        $SQLstr="SELECT * FROM arrange_content WHERE head_id='{$meeting['id']}';";
        $link->query($SQLstr);
        if($link->DS > 0)
        {
            $save_RS=$link->RS;
            $i=1;
            while($content=mysqli_fetch_assoc($save_RS))
            {
                echo "<fieldset class='field' id='upd_main_{$i}'>
                        <legend>計劃(會議子項):{$i}</legend>";
                echo  "計劃內容<a href='#load->Delete' onclick='drop_plans(true,{$i})'><img src='../../img/delete.png' /></a><br />";
                echo textarea("upd_content[{$i}]",$content['content'],3,40).
                    "<br /><input type='button' class='buttones' value='新增目標' onclick='add_target(true,{$i})' />";
                $SQLstrSub="SELECT * FROM arrange_plan WHERE content_id='{$content['id']}';";
                $link->query($SQLstrSub);
                if($link->DS > 0)
                {
                    $j=1;
                    while($target=mysqli_fetch_assoc($link->RS))
                    {
                        echo "<fieldset class='field_sub' id='upd_layer_{$i}_{$j}'>
                            <legend>目標(計劃{$i}子項):{$j}</legend>";
                        echo "計劃目標:".text("upd_target[{$i}][{$j}]",$target['target']).
                            "<a href='#load->Delete' onclick='drop_layer(true,\"{$i}:{$j}\");return false;'><img src='../../img/delete.png' /></a>
                            <br />負責人員:".text("upd_leader[{$i}][{$j}]",$target['leader'],100).
                            "<br />執行日期:".text("upd_start_date[{$i}][{$j}]",$target['start_date'],100).
                            "<br />完成日期:".text("upd_end_date[{$i}][{$j}]",$target['end_date'],100).
                            "<br />";
                        echo "<table id='upd_table_{$i}_{$j}'><tr><td class='form200'>資源與障礙</td><td class='form200'>處遇策略/步驟</td>
                            <td><a href='#load->Create' onclick='layer[{$i}]=new Array();add_countermeasures(true,\"{$i}:{$j}\");return false;'><img src='../../img/insert.png' /></a></td></tr>";
                        $res_obs=explode(':',$target['res_obs']);
                        $countermeasures=explode(':',$target['countermeasures']);
                        $k=1;
                        foreach($res_obs as $key=>$val)
                        {
                            echo "<tr id='upd_row_{$i}_{$j}_{$k}'><td>".text("upd_res_obs[{$i}][{$j}][{$k}]",$val);
                            echo "</td><td>".text("upd_countermeasures[{$i}][{$j}][{$k}]",$countermeasures[$key]);
                            echo "</td><td>
                            <a href='#load->Delete' value='{$i}:{$j}:{$k}' onclick='drop_counts(true,this.value)'><img src='../../img/delete.png' /></a>
                            </td></tr>";    
                            $k++;
                        }
                        echo "</table></fieldset>";    
                        $j++;
                    } 
                }
                else
                {
                    echo 'DateBase Error';
                }
                echo "</fieldset>";
                $i++;
            }
        }
        echo "</div>
        </td>
js
var meeters=2;
var x=1;
var main=new Array();
var layer=new Array();
function load_arrange_list(mode)
{
    var ajax=createAJAX();
    if(!ajax)
    {
        return false;
    }
    var uri='./load_arrange_list.php?time='+Date()+'&number='+arrange_number+'&mode=';
    if(mode=='meeting_mode')
    {
        uri+='meeting';
        if (getID('plan_mode') != null) 
        {
            closer('plan_mode');
        }
    }
    else
    {
        uri+='target';
        if (getID('meeting_mode') != null) 
        {
            closer('meeting_mode');
        }   
    }
    if (getID(mode) != null) 
    {
        opener(mode);
    }
    ajax.onreadystatechange = function()
    {
        if(ajax.readyState==4 && ajax.status == 200)
        {
            ref_zone(mode,ajax.responseText,true);       
        }
        else
        {
            ref_zone(mode,"<img src='../../img/ajax-loader.gif' />Loading..",true);
        }   
    }
    ajax.open ("GET", uri, true);
    ajax.send ("");
}
function php_mgs_pop(mgs)
{
    ref_zone('php_mgs',mgs,true);
}
function add_meeter()
{
    var par=getID('next_people');
    var new_row=document.createElement('div');
    var people=document.createElement('input');
    var dutys=document.createElement('input');
    var relations=document.createElement('input');
    var del=document.createElement('a');
    var img=document.createElement('img');
    var str1=document.createTextNode('姓名:');
    var str2=document.createTextNode('所屬單位/職別:');
    var str3=document.createTextNode('與個案關係:');
    new_row.id='rows_'+meeters;
    people.name='people['+meeters+']';
    people.type='text';
    people.style.width='50px';
    dutys.name='dutys['+meeters+']';
    dutys.type='text';
    dutys.style.width='100px';
    relations.name='relations['+meeters+']';
    relations.type='text';
    relations.style.width='100px';
    del.href='#Numbers->Delete';
    del.value=meeters;
    del.onclick=function()
    {
        drop_meeter(this.value);
    }
    img.src='../../img/delete.png';
    del.appendChild(img);
    new_row.appendChild(str1);
    new_row.appendChild(people);
    new_row.appendChild(str2);
    new_row.appendChild(dutys);
    new_row.appendChild(str3);
    new_row.appendChild(relations);
    new_row.appendChild(del);
    par.appendChild(new_row);
    meeters++;    
}
function drop_meeter(mode,id)
{
    var top_str='';
    if(mode)
    {
        top_str='upd_';
    }
    var par=getID(top_str+'next_people');
    var son=getID(top_str+'rows_'+id);
    par.removeChild(son);
}
function set_br(parnod)
{
    var br=document.createElement('br');
    parnod.appendChild(br);    
}
function add_plans(mode,pars)
{
    var action='';
    if(mode)
    {
        action='upd_';
        while(getID(action+'main_'+x)!=null)
        {
            x++;
        }
    }
    var max_par=getID(pars);
    var par_layer=document.createElement('fieldset');
    par_layer.id=action+'main_'+x;
    par_layer.className='field';
    var lener=document.createElement('legend');
    var title=document.createTextNode('計劃(會議子項):'+x);
    var str=document.createTextNode('計畫內容');
    var textareas=document.createElement('textarea');
    textareas.name=action+'content['+x+']';
    textareas.cols=40;
    textareas.rows=3;
    var close_span=document.createElement('span');
    close_span.className='form200r';
    var close_a=document.createElement('a');
    close_a.value=x;
    close_a.href='#Plan->Delete';
    close_a.onclick=function()
    {
         drop_plans(mode,this.value);
    } 
    var close_a_img=document.createElement('img');
    close_a_img.src='../../img/delete.png';
    close_a.appendChild(close_a_img);
    close_span.appendChild(close_a);
    var add_targets=document.createElement('input');
    add_targets.type='button'; 
    add_targets.value='新增目標';
    add_targets.className='buttones';
    var key=x;
    add_targets.onclick=function()
    {
        add_target(mode,key);
    }
    lener.appendChild(title);
    par_layer.appendChild(lener);
    par_layer.appendChild(str);
    par_layer.appendChild(close_span);
    set_br(par_layer);
    par_layer.appendChild(textareas);
    set_br(par_layer);
    par_layer.appendChild(add_targets);
    max_par.appendChild(par_layer); 
    main[x]=1;
    x++;   
}
function drop_plans(mode,id)
{
    var action='';
    if(mode)
    {
        action='upd_';
    }
    var par=getID(action+'plans');
    var son=getID(action+'main_'+id);
    par.removeChild(son);
}
function add_target(mode,id)
{   
    var action='';
    if(mode)
    {
        action='upd_';
        main[id]=1;
        while(getID(action+'layer_'+id+'_'+main[id])!=null)
        {
            main[id]++;
        }
    }
    var max_par=getID(action+'main_'+id);
    var par_layer=document.createElement('fieldset');
    par_layer.id=action+'layer_'+id+'_'+main[id];
    par_layer.className='field_sub';
    var lener=document.createElement('legend');
    var title=document.createTextNode('目標(計劃'+id+'子項):'+main[id]);
    //set field
    var close_span=document.createElement('span');
    close_span.className='form200r';
    var close_a=document.createElement('a');
    close_a.value=id+':'+main[id];
    close_a.href='#Plan->delete';
    close_a.onclick=function()
    {
        drop_layer(mode,this.value);
    }
    var close_a_img=document.createElement('img');
    close_a_img.src='../../img/delete.png';
    close_a.appendChild(close_a_img);
    close_span.appendChild(close_a);
    var str_target=document.createTextNode('計畫目標:');
    var str_admin=document.createTextNode('負責人員:');
    var str_start=document.createTextNode('執行日期:');
    var str_end=document.createTextNode('完成日期:');
    var sub_target_field=document.createElement('input');
    var sub_admin_field=document.createElement('input');
    var sub_start_field=document.createElement('input');
    var sub_end_field=document.createElement('input');
    sub_target_field.type='text';
    sub_target_field.name=action+'target['+id+']['+main[id]+']';
    sub_target_field.style.width='200px';
    sub_admin_field.type='text';
    sub_admin_field.name=action+'leader['+id+']['+main[id]+']';
    sub_admin_field.style.width='100px';
    sub_admin_field.type='text';
    sub_start_field.name=action+'start_date['+id+']['+main[id]+']';
    sub_start_field.style.width='100px';
    sub_start_field.type='text';
    sub_end_field.name=action+'end_date['+id+']['+main[id]+']';
    sub_end_field.style.width='100px';
    //create_field
    lener.appendChild(title);
    par_layer.appendChild(lener);
    par_layer.appendChild(str_target);
    par_layer.appendChild(sub_target_field);
    par_layer.appendChild(close_span);
    set_br(par_layer);
    par_layer.appendChild(str_admin);
    par_layer.appendChild(sub_admin_field);
    set_br(par_layer);
    par_layer.appendChild(str_start);
    par_layer.appendChild(sub_start_field);
    set_br(par_layer);
    par_layer.appendChild(str_end);
    par_layer.appendChild(sub_end_field);
    set_br(par_layer);
    //set_table
    var sub_table=document.createElement('table');
    sub_table.id=action+'table_'+id+'_'+main[id];
    var tr1=document.createElement('tr');
    var td1_1=document.createElement('td');
    td1_1.className='form200';
    var td1_2=document.createElement('td');
    td1_2.className='form200';
    var td1_3=document.createElement('td');
    var td_str1=document.createTextNode('資源與障礙');
    var td_str2=document.createTextNode('處遇策略/步驟');
    var td_a=document.createElement('a');
    td_a.href='#Res->Create'
    td_a.value=id+':'+main[id];
    td_a.onclick=function()
    {
        add_countermeasures(mode,this.value); 
        return false;  
    }
    td_a_img=document.createElement('img');
    td_a_img.src='../../img/insert.png';
    td_a.appendChild(td_a_img);
    td1_1.appendChild(td_str1);
    td1_2.appendChild(td_str2);
    td1_3.appendChild(td_a);
    //create_table
    tr1.appendChild(td1_1);
    tr1.appendChild(td1_2);
    tr1.appendChild(td1_3);
    sub_table.appendChild(tr1);
    //set layer
    par_layer.appendChild(sub_table);
    //create layer
    max_par.appendChild(par_layer);
    layer[id]=new Array();
    layer[id][main[id]]=1;
    main[id]++;  
}
function drop_layer(mode,id)
{
    var key=id.split(':');
    var action='';
    if(mode)
    {
        action='upd_';
    }
    var par=getID(action+'main_'+key[0]);
    var layer=getID(action+'layer_'+key[0]+'_'+key[1]);
    par.removeChild(layer);
}
function add_countermeasures(mode,id)
{
    var action='';
    var key=id.split(':');
    if(mode)
    {
        var action='upd_';
        layer[key[0]][key[1]]=1;
        while(getID(action+'row_'+key[0]+'_'+key[1]+'_'+layer[key[0]][key[1]])!=null)
        {
             layer[key[0]][key[1]]++;   
        }
    }
    var table=getID(action+'table_'+key[0]+'_'+key[1]);
    var new_row=document.createElement('tr');
    var new_td1=document.createElement('td');
    var new_td2=document.createElement('td');
    var new_td3=document.createElement('td');
    var new_res_feild=document.createElement('input');
    var new_counts_feild=document.createElement('input');
    var new_row_droper=document.createElement('a');
    var new_row_droper_img=document.createElement('img');
    new_row.id=action+'row_'+key[0]+'_'+key[1]+'_'+layer[key[0]][key[1]];
    new_res_feild.type='text';
    new_res_feild.name=action+'res_obs['+key[0]+']['+key[1]+']['+layer[key[0]][key[1]]+']';
    new_res_feild.style.width='200px';
    new_counts_feild.type='text';
    new_counts_feild.name=action+'countermeasures['+key[0]+']['+key[1]+']['+layer[key[0]][key[1]]+']';
    new_counts_feild.style.width='200px';
    new_row_droper.href='#Res->Delete';
    new_row_droper.value=key[0]+':'+key[1]+':'+layer[key[0]][key[1]];
    new_row_droper.onclick=function()
    {
        drop_counts(mode,this.value);
    }
    new_row_droper_img.src='../../img/delete.png';
    new_row_droper.appendChild(new_row_droper_img);
    new_td1.appendChild(new_res_feild);
    new_td2.appendChild(new_counts_feild);
    new_td3.appendChild(new_row_droper);
    new_row.appendChild(new_td1);
    new_row.appendChild(new_td2);
    new_row.appendChild(new_td3);
    table.appendChild(new_row);
    layer[key[0]][key[1]]++;
}
function drop_counts(mode,id)
{
    var key=id.split(':');
    var action='';
    if(mode)
    {
        action+='upd_';
    }
    var act_table=getID(action+'table_'+key[0]+'_'+key[1]);
    var row=getID(action+'row_'+key[0]+'_'+key[1]+'_'+key[2]);
    act_table.removeChild(row);
}
function reset_form(id)
{
    getID(id).reset();
    x=1;
    main=new Array();
    layer=new Array();
}
function load_record(mode,id)
{
    var uri='./load_arrange_record.php?time='+Date()+'&id='+id+'&mode=';
    if(mode)
    {
        uri+='meeting';
    }
    var ajax=createAJAX();
    if(!ajax)
    {
        return false;
    }
    closer('ins_arrange_record');
    getID('edit_arrange_record').style.display='';
    ajax.onreadystatechange = function()
    {
        if(ajax.readyState==4 && ajax.status == 200)
        {
            ref_zone('edit_arrange_record',ajax.responseText,true);       
        }
        else
        {
            ref_zone('edit_arrange_record','<img src="../../img/ajax-loader.gif" />',true);   
        }   
    }
    ajax.open ("GET", uri, true);
    ajax.send ("");
    
}
function load_lmp(made,id)
{
    var action='long_img';
    var newY=tempY+5;
    getID(action).style.top=newY+'px';
    opener(action);
}
PS.getID()=document.getElementById()
opener(),closer()改變一個元素的display屬性值

原始討論: http://twpug.net/x/modules/newbb/viewtopic.php?topic_id=4698

評論

  • edited 十一月 2009
    查出來了...節點元素要設定在<tbody id='...'>.....
    看樣子以後最好不要省略<tbody>了...
    最近一直發生這種鬼打牆bug,真的會出人命(泣
    不過說真的,遞迴一直都這麼討厭,
    new_counts_feild.name=action+'countermeasures+']+']][key[1]]+']';
    像這種神碼自己都快看不懂了...
Sign In or Register to comment.