assign.js

来自「由javascript调用serlet后台程序」· JavaScript 代码 · 共 95 行

JS
95
字号
var XMLHttpReq;
var res;
 	//创建XMLHttpRequest对象     
var number; 
function createXMLHttpRequest() {
    if (window.XMLHttpRequest) { //Mozilla 浏览器
        XMLHttpReq = new XMLHttpRequest();
    } else {
        if (window.ActiveXObject) { // IE浏览器
            try {
                XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e) {
                try {
                    XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (e) {
                }
            }
        }
    }
}
function sendRequest(url) {
    createXMLHttpRequest();
    XMLHttpReq.open("GET", url, true);
    XMLHttpReq.onreadystatechange = processResponse;//指定响应函数
    XMLHttpReq.send(null);  // 发送请求
}
function processResponse() {
    if (XMLHttpReq.readyState == 4) { // 判断对象状态
        if (XMLHttpReq.status == 200) { // 信息已经成功返回,开始处理信息
              res = XMLHttpReq.responseText;
			  
                window.alert("恭喜您又完成一项任务");
				window.alert(res);
                var row = createrow();
	            datatablebody.appendChild(row);
			

               

		}
    }
}
function onCheckX(id){
	var number=id;
	window.alert("完成任务");
	window.alert(id);

     datatable=document.getElementById("a");
	datatablebody=document.getElementById("b");
	datadiv = document.getElementById(id);
	child=datadiv.getAttribute("name");
	window.alert(child);

 cleardata(child);



	
sendRequest("/servlet2?number=" + number);
	}
function createrow(){
	var length,tbody, row,cell,inptu,txtnode;
	length=datatablebody.childNodes.length;
	tbody= document.createElement("<tbody>");
	row = document.createElement("<tr>");
	cell= document.createElement("<td>");

	txtnode = document.createTextNode(res);

	cell.appendChild(txtnode);
    cell.setAttribute("align","left");
	cell.setAttribute("id",number);
	cell.setAttribute("style","padding-left:10px");
	cell.setAttribute("value",number);
	cell.setAttribute("name",length);
	cell.setAttribute("onclick","onCheckY(this.value)");
	row.appendChild(cell);
    tbody.appendChild(row);
	return tbody;
}
//清除提示框
function cleardata(id){
	  
           var ind = datatable.childNodes.length;
       
         for(var i = id+1; i<=ind-1; i++){
		datatable.childNodes[i].name=i-1;
	}
	
		datatable.removeChild(datatable.childNodes[id]);

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?