r.setAttribute("id",list[i].childNodes[0].firstChild.nodeValue);
tr.onclick = function(e){add_Event(e)};
var td = tr.insertCell(0);
td.innerHTML = list[i].childNodes.firstChild.nodeValue;
}
}
}
}
}
ajax.send(null);//提交请求,参数为null
}
window.load = Read();
function add_Event(e){
e = e || window.event;
var elem = e.target || e.srcElement;
if(elem.tagName == "TD"){
elem = elem.parentNode;
}
var table = elem.parentNode;
for(var i=0;i<table.rows.length;i++){
table.rows[i].style.background="";
}
elem.style.background="#999ccc";
document.getElementById("hid_id").value = elem.id;
}
//删除数据函数
function del_Data(){
var mesage = document.getElementById("msg");//获取显示操作信息的span
mesage.innerHTML="正在删除请稍候......";
var table = document.getElementById("a");//获取要显示数据的表格
if(table.rows.length == 0){
mesage.innerHTML = "表格内没有数据可供删除!";
return;
}
var id = document.getElementById("hid_id");
if(id.value.length == 0){
mesage.innerHTML = "您还没有选择数据!";
return;
}
var ajax = ajax_xmlhttp();//定义xmlhttprequest对象
ajax.open("post","Add_Del_data.asp?action=del",true);//设置请求方式,请求文件,异步请求
var param = "id="+escape(id.value);//获取要删除数据的id
ajax.onreadystatechange = function(){
if(ajax.readyState==4){
if(ajax.status==200){
var xml = ajax.responseXML;
var msg = xml.getElementsByTagName("msg")[0].firstChild.nodeValue;
if(msg == 0){
mesage.innerHTML = "成功删除数据!";
var tr = document.getElementById(id.value);//获取当前选择的行
tr.parentNode.removeChild(tr);//引用该行的父元素.然后删除该行.
id.value="";//删除完成清空文本框里的值,
}
if(msg == 1){
mesage.innerHTML = "服务端发生错误,删除失败!";
}
}
}
}
ajax.setRequestHeader("content-type","application/x-www-form-urlencoded");
ajax.send(param);
}
//提交数据函数
function add_Post(){
var msgaes = document.getElementById("msg");//用来显示提示信息
var str = document.getElementById("str");//接收输入的内容
if(str.value.length == 0){
msgaes.innerHTML = "不接受空内容!"
return;
}
msgaes.innerHTML = "正在提交";
var ajax = ajax_xmlhttp();//定义xmlhttprequest对象
ajax.open("post","Add_Del_data.asp?action=add",true);//设置请求方式,请求文件,异步请求
var param = "str="+escape(str.value);//获取你输入的内容,注意这里的str,服务端将接收str中的值
ajax.onreadystatechange = function(){
if(ajax.readyState==4){
if(ajax.status==200){
var msg = ajax.responseXML.getElementsByTagName("msg");//获取服务端返回的msg标签
if(msg[0].firstChild.nodeValue == 0){
var max_num = ajax.responseXML.getElementsByTagName("count")[0].firstChild.nodeValue;
var t = document.getElementById("a");
var tr = t.insertRow(0);
tr.setAttribute("id",max_num);
tr.onclick = function(e){add_Event(e)};
var td = tr.insertCell(0);
td.innerHTML = str.value;
str.value = "";
msgaes.innerHTML = "添加完成";
}
else if(msg[0].firstChild.nodeValue == 3){
msgaes.innerHTML = "不接受空的内容";
return;
}
else if(msg[0].firstChild.nodeValue == 1){
msgaes.innerHTML = "服务端发生错误,数据添加失败!";
return;
}
else{
msgaes.innerHTM