function el(id){ return document.getElementById(id); } window.onload = function(){ //alert(abc); el("div1").oncontextmenu = function(ev){ showMenu(ev); return false; }; document.onmousedown = function(){if(!over)hideMenu();}; }; var over = false; var menu = null; function showMenu(ev){ ev = ev || window.event; hideMenu(); var e = ev.srcElement || ev.target; if(e.tagName=="TH") return; var x = ev.pageX || ev.clientX + document.documentElement.scrollLeft; var y = ev.pageY || ev.clientY + document.documentElement.scrollTop; menu = document.createElement("DIV"); menu.className = "menu"; menu.style.left = x+4+"px"; menu.style.top = y+"px"; document.body.appendChild(menu); var id = e.parentNode.getElementsByTagName("td")[0].innerHTML; e.parentNode.id = "tr_"+id; var sname = document.location.pathname.substring(7,location.pathname.length).toString(); var s = "详细信息"; s += "刷新"; //s += "修改用户信息"; //s += "删除该条记录"; s = s.replace(/{id}/g, id); s = s.replace(/{sname}/g, sname); menu.innerHTML = s; menu.onmouseover = function(){over=true;}; menu.onmouseout = function(){over=false;}; } function hideMenu(){ if(menu){ document.body.removeChild(menu); menu = null; } } function refresh(sname){ var req = getReq(); req.open("GET", sname+"?refresh=1&id=", true); /*req.onreadystatechange = function(){ if(req.readyState==4) { el("bod").innerHTML = req.responseText; } };*/ req.send(null); } function showInfo(id,sname){ hideMenu(); shideBody(); el("tit").innerHTML = "查看用户的详细信息"; el("bod").innerHTML = "loading..."; el("bot").innerHTML = ""; var req = getReq(); req.open("GET", sname+"?getinfo=1&id="+id, true); req.onreadystatechange = function(){ if(req.readyState==4){ el("bod").innerHTML = req.responseText; } }; req.send(null); } function editInfo(id){ hideMenu(); shideBody(); el("tit").innerHTML = "编辑用户信息"; el("bod").innerHTML = "loading..."; el("bot").innerHTML = " "; var tds = el("tr_"+id).getElementsByTagName("td"); var boy = tds[2].innerHTML == "男"; var s = ""; s += ""; s += ""; s += ""; s += "
姓名
性别
年龄
"; el("bod").innerHTML = s; } function deleteInfo(id){ hideMenu(); if(!confirm("确定要删除该记录吗?"))return; removeRow(el("tr_"+id)); var req = getReq(); req.open("GET", "default.aspx?delete=1&id="+id, true); req.onreadystatechange = function(){}; req.send(null); } function doEdit(id){ var puts = el("bod").getElementsByTagName("input"); if(isNaN(puts[3].value)){ puts[3].select();return; } var tds = el("tr_"+id).getElementsByTagName("td"); tds[1].innerHTML = puts[0].value; tds[2].innerHTML = puts[1].checked?"男":"女"; tds[3].innerHTML = puts[3].value; var data = "name="+ escape(tds[1].innerHTML); data += "&sex="+ escape(tds[2].innerHTML); data += "&age="+ escape(tds[3].innerHTML); var req = getReq(); req.open("POST", "default.aspx?edit=1&id="+id, true); req.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); req.onreadystatechange = function(){}; req.send(data); cancelShide(); } var shield; function shideBody() { shield = document.createElement("DIV"); shield.id = "shield"; shield.style.position = "absolute"; shield.style.left = "0px"; shield.style.top = "0px"; shield.style.width = "100%"; shield.style.height = document.documentElement.scrollHeight+"px"; shield.style.background = "#333333"; shield.style.textAlign = "center"; shield.style.zIndex = "10"; shield.style.filter = "alpha(opacity=0)"; shield.style.opacity = 0; document.body.appendChild(shield); this.setOpacity = function(obj,opacity){ if(opacity>=1)opacity=opacity/100; try{ obj.style.opacity=opacity; }catch(e){} try{ if(obj.filters.length>0 && obj.filters("alpha")){ obj.filters("alpha").opacity=opacity*150; }else{ obj.style.filter="alpha(opacity=\""+(opacity*150)+"\")"; } }catch(e){} } var c = 0; this.doAlpha = function(){ if (++c > 20){clearInterval(ad);return 0;} setOpacity(shield,c); } var ad = setInterval("doAlpha()",1); el("divh").style.display = ""; el("divh").style.marginTop = -75+document.documentElement.scrollTop + "px"; } function cancelShide() { if(el("divh")) { el("divh").style.display = "none"; } if(shield) { document.body.removeChild(shield); shield = null; } } function getReq() { var oHttpReq = null; if(window.ActiveXObject) oHttpReq = new ActiveXObject("MSXML2.XMLHTTP"); else if(window.createRequest) oHttpReq = window.createRequest(); else oHttpReq = new XMLHttpRequest(); return oHttpReq; } function removeRow(e) { e.style.backgroundColor = "#ff0000"; setTimeout(function(){e.style.backgroundColor = "#ffcccc";},100); setTimeout(function(){e.style.backgroundColor = "MistyRose";},300); setTimeout(function(){e.style.display = "none";},450); }