⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 index.js

📁 用最近的dojo1.2.1制作前端的ajax购书网站
💻 JS
📖 第 1 页 / 共 2 页
字号:
					},					error: function(){alert("error8");}				});			}		}		}	} });/*--------------------------------------------------------------------*//*-----------------------Login----------------------------------------*/var UserID = "";function submission(){var wLogin = "false";	if(dojo.cookie("check")=="check"){		alert("You have entered the system");	}	else{		dojo.xhrGet({			url:"servlet/server.servlet.LogIn",			timeout: 15000,			form:"loginForm",			load:function(result,ioArgs){				//alert(typeof(result));				wLogin = result;				//alert(wLogin);				if(result == "true"){					dojo.cookie("check","check");					UserID = dijit.byId("consumer_login_name").getValue();					dijit.byId("consumer_login_name").setValue("");					dijit.byId("consumer_login_password").setValue("");					var user = dojo.byId("placeUser");					user.innerHTML = " , "+UserID;//add user Name						dojo.cookie("UserID",UserID);					//alert(UserID);					getCartBook();					}				else if(result == "false"){					alert("Please confirm your User's ID and Password");				}				else{					alert("Error");				}			},			error:function(ioArgs){alert("error3");}		});	}		//alert(UserID);		//alert(typeof(wLogin)+":"+wLogin);		}function getCartBook(){			dojo.xhrGet({				url:"servlet/server.servlet.LoadCart",				timeout: 10000,				content:{op:"loadCart",userID:UserID},				handleAs: "json",				load:function(result,ioArgs){					var Cartbook = result;					clearList();					booklist.insertNodes(false,Cartbook);					booklist.startup();				},				error:function(ioArgs){}			});}/*--------------------------------------------------------------------*//*-----------------------Logout---------------------------------------*/function logout(){		UserID="";		historyInitial();	if(dojo.cookie("check") == "check"){		dojo.cookie("check","");		dojo.cookie("userID","");		cart.selectAll();		cart.deleteSelectedNodes();		cart.clearItems();		var user = dojo.byId("placeUser");		user.innerHTML = "";//add user Name		UserID = "";		bookID = "";		dojo.cookie("id",bookID);	}}/*--------------------------------------------------------------------*//*-----------------------balance table--------------------------------*//*function addLoadEvent(func) {   var oldonload = window.onload;   if (typeof window.onload != 'function') {     window.onload = func;   } else {    window.onload = function() {       oldonload();       func();     }   } } */function clearData(){	dojo.byId("balanceBody").innerHTML = "";	dijit.byId("selectAddress").setValue("New Address");	dijit.byId("hider2").setDisabled(true);	dijit.byId("horizontalSlider").setValue("0");	dojo.byId("showResult").innerHTML = "";}////////////////Step 1function getElementsByClassName(className, tag, elm){     var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");     var tag = tag || "*";     var elm = elm || document;     var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);     var returnElements = [];     var current;     var length = elements.length;     for(var i=0; i<length; i++){         current = elements[i];         if(testClass.test(current.className)){             returnElements.push(current);         }     }     return returnElements; } function addClassName(elm, className){     var currentClass = elm.className;     if(!new RegExp(("(^|\\s)" + className + "(\\s|$)"), "i").test(currentClass)){         elm.className = currentClass + ((currentClass.length > 0)? " " : "") + className;     }     return elm.className; } function removeClassName(elm, className){     var classToRemove = new RegExp(("(^|\\s)" + className + "(\\s|$)"), "i");     elm.className = elm.className.replace(classToRemove, "").replace(/^\s+|\s+$/g, "");     return elm.className; } function makeTheTableHeadsHighlight() {     // get all the td's in the heart of the table...     var table = document.getElementById('balanceTable');     var tbody = table.getElementsByTagName('tbody');     var tbodytds = table.getElementsByTagName('td');          // and loop through them...     for (var i=0; i<tbodytds.length; i++) {          // take note of their default class name         tbodytds[i].oldClassName = tbodytds[i].className;              // when someone moves their mouse over one of those cells...         tbodytds[i].onmouseover = function() {          // attach 'on' to the pointed cell             addClassName(this,'on');                  // attach 'on' to the th in the thead with the same class name             var topheading = getElementsByClassName(this.oldClassName,'th',table);             addClassName(topheading[0],'on');                  // attach 'on' to the far left th in the same row as this cell             var row = this.parentNode;             var rowheading = row.getElementsByTagName('th')[0];             addClassName(rowheading,'on');         }          // ok, now when someone moves their mouse away, undo everything we just did.              tbodytds[i].onmouseout = function() {          // remove 'on' from this cell             removeClassName(this,'on');                  // remove 'on' from the th in the thead             var topheading = getElementsByClassName(this.oldClassName,'th',table);             removeClassName(topheading[0],'on');     // remove 'on' to the far left th in the same row as this cell             var row = this.parentNode;             var rowheading = row.getElementsByTagName('th')[0];             removeClassName(rowheading,'on');         }     } } //addLoadEvent(makeTheTableHeadsHighlight);/*var data = [{name:"name1",price:"1",discount:"0.1"},{name:"name2",price:"2",discount:"0.2"},{name:"name3",price:"3",discount:"0.3"},{name:"name4",price:"4",discount:"0.4"}];*/var data;function addProductToTbody(){	for(var i = dojo.byId("balanceBody").rows.length-1; i>-1; --i){		dojo.byId("balanceBody").deleteRow(i);	}	//alert(dojo.cookie("id"));	if(dojo.cookie("id") != null){	dojo.xhrGet({		url:"servlet/server.servlet.Balance",		timeout: 10000,		content:{op:"1",id:dojo.cookie("id")},		handleAs: "json",		load:function(result,ioArgs){			data = result;			//alert(data.length);			var tdClass = ["productID","ProductPrice","productDiscount","productDP","quantity"];			var tbody = document.getElementById("balanceBody");			for(var i=0; i<data.length;++i){				var tr = document.createElement("tr");				//tr.id = data[i].name;				var th = document.createElement("th");				th.className = "productName";				th.innerHTML = data[i].name;				tr.appendChild(th);				for(var k=0; k<tdClass.length;++k){					var td = document.createElement("td");					td.className = tdClass[k];					switch(k){						case 0:							td.innerHTML=data[i].id;							break;						case 1:							td.innerHTML=parseFloat(data[i].price).toFixed(2);							break;						case 2:							td.innerHTML=parseFloat(data[i].discount).toFixed(2);							break;						case 3:							var num = parseFloat(data[i].price) * parseFloat(data[i].discount);							td.innerHTML=num.toFixed(2);							break;						case 4:							var div = document.createElement("div");							//div.id = data[i].id;							//input.style = "{length:50px}";							td.appendChild(div);							var foo = new dijit.form.NumberSpinner({								constraints:{min:1,max:50,places:0},								value:"1",								smallDelta:"1",								onChange: calculation,								intermediateChanges:"true"								},div);							foo.startup();							break;						default:break;					}					tr.appendChild(td);				}				tbody.appendChild(tr);			}			calculation();			makeTheTableHeadsHighlight();		},		error:function(ioArgs){alert("Error:"+ioArgs);}	});	}}function calculation(){	dojo.byId("totalprice").innerHTML = "";	dojo.byId("discountprice").innerHTML = "";	dojo.byId("totalsaving").innerHTML = "";	//var ProductIDArray = getElementsByClassName("productID");	var PriceArray = getElementsByClassName("ProductPrice");	var discountPriceArray = getElementsByClassName("productDP");	var quantityArray = getElementsByClassName("quantity");	var totalPrice = 0;	var totalDiscountPrice = 0;	var totalSaving = 0;	for(var i=1; i<PriceArray.length; ++i){		totalPrice += parseFloat(PriceArray[i].innerHTML) * dijit.byNode(quantityArray[i].firstChild).getValue();		totalDiscountPrice += parseFloat(discountPriceArray[i].innerHTML) * dijit.byNode(quantityArray[i].firstChild).getValue();	}	dojo.byId("totalprice").innerHTML = parseFloat(totalPrice).toFixed(2);	dojo.byId("discountprice").innerHTML = parseFloat(totalDiscountPrice).toFixed(2);	dojo.byId("totalsaving").innerHTML = parseFloat(totalPrice - totalDiscountPrice).toFixed(2);}//////////////Step 2function ChangeAddress(){	var Selected = dijit.byId("selectAddress");	var BalanceAddress = dijit.byId("balanceAddress");	if(Selected.getValue() == "Member Address"){		if (dojo.cookie("check") == "check") {			dojo.xhrGet({				url: "servlet/server.servlet.Balance",				timeout: 10000,				//handleAs: "text/html",				content: {					op: "2",					MemberAddress: UserID				},				load: function(result, ioArgs){					BalanceAddress.setValue(result);				},				error: function(){					alert("error 10");				}			});			BalanceAddress.setDisabled(true);		}		else{			Selected.setValue("New Address");			alert("You have not login");		}	}	else if(Selected.getValue() == "New Address"){		BalanceAddress.setValue("");		BalanceAddress.setDisabled(false);	}	else{		alert(Selected.value);	}}/////////////////HorizontalSliderfunction ChangeStep(arg){	var Step1 = dojo.byId("step1");	var Step2 = dojo.byId("step2");	var Finish = dojo.byId("Finish");	var hider2 = dijit.byId("hider2");	if(arg == "0"){		Step1.style.display = "block";		Step2.style.display = "none";		Finish.style.display = "none";		hider2.setDisabled(true);	}	else if(arg == "1.5"){		Step1.style.display = "none";		Step2.style.display = "block";		Finish.style.display = "none";		hider2.setDisabled(true);	}	else if(arg == "3"){		Step1.style.display = "none";		Step2.style.display = "none";		Finish.style.display = "block";		var SelectedAddress = dijit.byId("selectAddress").getValue();		var balanceAddress = dijit.byId("balanceAddress").getValue();		var product_length = dojo.byId("balanceBody").rows.length;		if(product_length  == 0){			dojo.byId("showResult").innerHTML = "You haven't buy any thing";		}		else{					if(SelectedAddress == "New Address"){			//alert(balanceAddress);				if( balanceAddress == "" || balanceAddress == null){					dojo.byId("showResult").innerHTML = "You forget to input your address";				}				else{					hider2.setDisabled(false);				}			}			else{				hider2.setDisabled(false);			}		}	}}function SendBalance(){	var bookCookie = dojo.cookie("id");	var SelectedAddress = dijit.byId("selectAddress").getValue();	var balanceAddress = dijit.byId("balanceAddress").getValue();	var temp_user = "";	if(SelectedAddress == "New Address"){		SelectedAddress = balanceAddress;	}	var cash = dijit.byId("cash");	var credit = dijit.byId("credit");	var paymethod;	var Quantity = "";	if(cash.checked){		//alert("cash");		paymethod = "cash";	}	else if(credit.checked){		//alert("credit");		paymethod = "credit";	}	var quantityArray = getElementsByClassName("quantity");	for(var i=1; i<quantityArray.length; ++i){		Quantity += dijit.byNode(quantityArray[i].firstChild).getValue().toString()+" ";	}	if(UserID == "" || UserID == null){		temp_user = "temp_user";	}	else{		temp_user = UserID;	}	dojo.xhrGet({		url:"servlet/server.servlet.Balance",		timeout:10000,		content:{op:"3",ids:dojo.cookie("id"),Address:SelectedAddress,quantity:Quantity,Pay:paymethod,userID:temp_user},		load:function(result,ioArgs){			if(result == "true"){				dojo.byId("showResult").innerHTML = "Congratulation! You Succeed to Finish the Balance";				bookID = "";				//dojo.cookie("id",bookID);				cart.selectAll();				cart.deleteSelectedNodes();				cart.clearItems();			}		},		error:function(){alert("error11");}	});	if(dojo.cookie("check") == "check"){		var str = dojo.cookie("id");		var array = str.split(' ');		for(var i = 0; i < array.length; ++i){			dojo.xhrGet({				url: "servlet/server.servlet.Cart",				timeout: 10000,				content:{method:"sub",subitem:array[i],userID:UserID},				load: function(response,ioArgs){					},				error: function(){alert("error8");}			});		}	}	dojo.cookie("id",bookID);	//清空购物车,重置Balance模块}function loadAllinformation(){	var ids = dojo.cookie("id");	var check = dojo.cookie("check");	if(check == "check"){		var tmp_user = dojo.cookie("UserID");		if(tmp_user != null){			dojo.byId("placeUser").innerHTML = tmp_user;			UserID = tmp_user;			getCartBook();		}		else{			UserID = "";			//alert(UserID);		}	}	if(ids == "" || ids == null){	}	else{		//alert(ids);		dojo.xhrGet({			url:"servlet/server.servlet.ReurnBookInfo",			timeout: 10000,			content:{ids:ids},			handleAs: "json",			load:function(result,ioArgs){				var Cartbook = result;				//clearList();				cart.insertNodes(false,Cartbook);				cart.startup();							},			error:function(ioArgs){alert("error:"+ioArgs);}		});			}			}window.onload = loadAllinformation;/*--------------------------------------------------------------------*/

⌨️ 快捷键说明

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