|
function
add(){
var
Node_name=document.getElementsByName(
"name"
)[0];
var
Node_phone=document.getElementsByName(
"phone"
)[0];
var
Node_mail=document.getElementsByName(
"mail"
)[0];
var
Element_tr=document.createElement(
"tr"
);
var
select_td=document.createElement(
"td"
);
var
input_node=document.createElement(
"input"
);
input_node.setAttribute(
"name"
,
"items"
);
input_node.setAttribute(
"type"
,
"checkbox"
);
select_td.appendChild(input_node);
var
name_td=document.createElement(
"td"
);
var
name_text=document.createTextNode(Node_name.value);
name_td.appendChild(name_text);
var
phone_td=document.createElement(
"td"
);
var
phone_text=document.createTextNode(Node_phone.value);
phone_td.appendChild(phone_text);
var
mail_td=document.createElement(
"td"
);
var
mail_text=document.createTextNode(Node_mail.value);
mail_td.appendChild(mail_text);
Element_tr.appendChild(select_td);
Element_tr.appendChild(name_td);
Element_tr.appendChild(phone_td);
Element_tr.appendChild(mail_td);
var
Element_table=document.getElementById(
"table"
);
Element_table.appendChild(Element_tr);
}
function
All(){
var
check_node=document.getElementsByName(
"items"
);
for
(
var
i = 0; i < check_node.length; i++) {
check_node[i].checked=
"checked"
;
}
}
function
other(){
var
check_node=document.getElementsByName(
"items"
);
for
(
var
i = 0; i < check_node.length; i++) {
if
(check_node[i].checked){
check_node[i].checked=
null
;
}
else
{
check_node[i].checked=
"checked"
;
}
}
}
function
Delete(){
var
check_node=document.getElementsByName(
"items"
);
//alert(check_node.length);
for
(
var
i = 0; i < check_node.length; i++) {
if
(check_node[i].checked){
//alert(check_node[i].checked);
var
delete_tr_node=check_node[i].parentNode.parentNode;
//alert(delete_tr_node.nodeName);
var
Element_table=document.getElementById(
"table"
);
Element_table.removeChild(delete_tr_node);
}
}
}
For循环颠倒一下就可以了,现在循环是从小到大,改成从大到小就可以了,因为数组长度在变化