28,406
社区成员
发帖
与我相关
我的任务
分享
<script language="javascript">
httpobj=getHTTPObject();
function getdeptxml()
{
if(httpobj)
{
httpobj.open("POST","departmentinfo.asp",true);
httpobj.onreadystatechange=gotResult;
httpobj.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=gb2312');
httpobj.send(null);
}
}
function gotResult()
{
if (httpobj.readyState==4)
{
if(httpobj.status==200)
{
var xmldoc=new ActiveXObject("Microsoft.XMLDOM");
xmldoc.async=false;
xmldoc.loadXML(httpobj.responseText);
cleartable(dept_table);
var i,tr,td;
i=0;
while(xmldoc.documentElemet.childNodes.item(i)!=null)
{
tr=dept_table.insertRow();
td=tr.insertCell();
td.innerHTML=xmldoc.documentElement.childNodes.item(i).childNodes.item(0).text;
td=tr.insertCell();
td.innerHTML="<input name=cell"+i+"1 type=text value="+unescape(xmldoc.documentElement.childNodes.item(i).chidNodes.item(1).text)+">";
td=tr.insertCell();
td.innerHTML="<input name=cell"+i+"2 type=text value="+unescape(xmldoc.documentElement.childNodes.item(i).chidNodes.item(2).text)+">";
td=tr.insertCell();
td.innerHTML="<input type=button value=修改 onclick=editdept("+i+","+(xmldoc.documentElement.childNodes.item(i).nodeName).substr(3)+")>";
td=tr.insertCell();
td.innerHTML="<input type=button value=删除 onclick=deletedept("+(xmldoc.documentElement.childNodes.item(i).nodeName).substr(3)+")>";
i=i+1;
}
}
}
}
function cleartable(obj)
{
for(var k=obj.rows.length-1;k>=1;k--)
obj.deleteRow(k);
}
function editdept(i,id)
{
if(document.getElementById("cell"+i+"1").value=="")
{
alert("部门名称不能为空");
return;
}
if(httpobj)
{
httpobj.open("POST","edit_department_do.asp",true);
httpobj.onreadystatechange=gotResult_edit;
httpobj.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=gb2312');
param="id="+id+"&deptname="+escape(document.getElementById("cell"+i+"1").value)+"&remark="+escape(document.getElementById("cell"+i+"2").value);
httpobj.send(param);
}
}
function gotResult_edit()
{
if(httpobj.readyState==4)
{
if(httpobj.status==200)
{
if(httpobj.responseText=="success")
window.alert("数据修改成功");
else if(httpobj.responseText=="failed")
window.alert("部门名称发生重复");
}
}
}
function deletedept(id)
{
if(httpobj)
{
httpobj.open("POST","del_department_do.asp",true);
httpobj.onreadystatechange=gotResult_del;
httpobj.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=gb2312');
param="id="+id;
httpobj.send(param);
}
}
function gotResult_del()
{
if(httpobj.readyState==4)
{
if(httpobj.status==200)
{
if(httpobj.responseText=="success")
{
window.alert("数据删除成功");
getdeptxml();
}
else
window.alert("数据删除失败");
}
}
}
function getHTTPObject()
{
var xmlhttp=false;
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
if(xmlhttp.overrideMimeType)
{
xmlhttp.overrideMimeType('text/xml');
}
}
else
{
try
{
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(E)
{
xmlhttp=false;
}
}
}
return xmlhttp;
}
</script>
<table id="dept_table" width="100%" border="1" cellspacing="0" cellpadding="0" bordercolorlight="#000000" bordercolordark="#FFFFFF">
<tr>
<td width="70" align="center" class="borderon2">序号</td>
<td width="355" align="center" class="borderon2">部门名称</td>
<td width="308" align="center" class="borderon2">描述</td>
<td width="91" align="center" class="borderon2">修改</td>
<td width="84" align="center" class="borderon2">删除</td>
</tr>
</table>
<!--#include file="conn.asp"-->
<%
id=request("id")
deptname=replace(unescape(request("deptname")),"'","''")
ifexists(deptname)
remark=replace(unescape(request("remark")),"'","''")
sql="update department set deptname='"&deptname&"',remark='"remark"' where id="&id
conn.execute(sql)
response.Write "success"
sub ifexists(dept)
set tmp=server.CreateObject("adodb.recordest")
tmp.open "select deptname from department where deptname='"&dept&"' and id<>"&id,conn
if not tmp.eof then
response.Write "failed"
response.end
end if
end sub
%>
<script language="javascript">
httpobj=getHTTPObject();
function getdeptxml()
{
if(httpobj)
{
httpobj.open("GET","departmentinfo.asp",true);
httpobj.onreadystatechange=gotResult;
httpobj.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=gb2312');
httpobj.send(null);
}
}
function gotResult()
{
if (httpobj.readyState==4)
{
if(httpobj.status==200)
{
var xmldoc=new ActiveXObject("Microsoft.XMLDOM");
xmldoc.async=false;alert(httpobj.responseText)
xmldoc.loadXML(httpobj.responseText);
cleartable(dept_table);
var i,tr,td;
i=0;
while(xmldoc.documentElement.childNodes.item(i)!=null)
{
tr=dept_table.insertRow();
td=tr.insertCell();
td.innerHTML=xmldoc.documentElement.childNodes.item(i).childNodes.item(0).text;
td=tr.insertCell();
td.innerHTML="<input name=cell"+i+"1 type=text value="+unescape(xmldoc.documentElement.childNodes.item(i).childNodes.item(1).text)+">";
td=tr.insertCell();
td.innerHTML="<input name=cell"+i+"2 type=text value="+unescape(xmldoc.documentElement.childNodes.item(i).childNodes.item(2).text)+">";
td=tr.insertCell();
td.innerHTML="<input type=button value=修改 onclick=editdept("+i+","+(xmldoc.documentElement.childNodes.item(i).nodeName).substr(3)+")>";
td=tr.insertCell();
td.innerHTML="<input type=button value=删除 onclick=deletedept("+(xmldoc.documentElement.childNodes.item(i).nodeName).substr(3)+")>";
i=i+1;
}
}
}
}
function cleartable(obj)
{
for(var k=obj.rows.length-1;k>=1;k--)
obj.deleteRow(k);
}
function editdept(i,id)
{
if(document.getElementById("cell"+i+"1").value=="")
{
alert("部门名称不能为空");
return;
}
if(httpobj)
{
httpobj.open("POST","edit_department_do.asp",true);
httpobj.onreadystatechange=gotResult_edit;
httpobj.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=gb2312');
param="id="+id+"&deptname="+escape(document.getElementById("cell"+i+"1").value)+"&remark="+escape(document.getElementById("cell"+i+"2").value);
httpobj.send(param);
}
}
function gotResult_edit()
{
if(httpobj.readyState==4)
{
if(httpobj.status==200)
{
if(httpobj.responseText=="success")
window.alert("数据修改成功");
else if(httpobj.responseText=="failed")
window.alert("部门名称发生重复");
}
}
}
function deletedept(id)
{
if(httpobj)
{
httpobj.open("POST","del_department_do.asp",true);
httpobj.onreadystatechange=gotResult_del;
httpobj.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=gb2312');
param="id="+id;
httpobj.send(param);
}
}
function gotResult_del()
{
if(httpobj.readyState==4)
{
if(httpobj.status==200)
{
if(httpobj.responseText=="success")
{
window.alert("数据删除成功");
getdeptxml();
}
else
window.alert("数据删除失败");
}
}
}
function getHTTPObject()
{
var xmlhttp=false;
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
if(xmlhttp.overrideMimeType)
{
xmlhttp.overrideMimeType('text/xml');
}
}
else
{
try
{
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(E)
{
xmlhttp=false;
}
}
}
return xmlhttp;
}
window.onload=function(){
getdeptxml()
}
</script>
<table id="dept_table" width="100%" border="1" cellspacing="0" cellpadding="0" bordercolorlight="#000000" bordercolordark="#FFFFFF">
<tr>
<td width="70" align="center" class="borderon2">序号</td>
<td width="355" align="center" class="borderon2">部门名称</td>
<td width="308" align="center" class="borderon2">描述</td>
<td width="91" align="center" class="borderon2">修改</td>
<td width="84" align="center" class="borderon2">删除</td>
</tr>
</table>
<!--#include file="conn.asp"-->
<?xml version="1.0" encoding="gb2312"?>
<datalist>
<%
set rs=server.CreateObject("adodb.recordset")
sql="select * from department"
rs.open sql,conn
i=1
while not rs.eof
response.Write "<rec"&rs("id")&">"
response.Write "<r0>"&i&"</r0>"
response.Write "<r1>"&escape(rs("deptname"))&"</r1>"
response.Write "<r2>"&escape(rs("remark"))&"</r2>"
response.Write "</rec"&rs("id")&">"
rs.movenext
i=i+1
wend
%>
</datalist>