?? util.js
字號:
function getCookieVal(offset)
{
var endstr = document.cookie.indexOf(";", offset);
if(endstr == -1)
{
endstr = document.cookie.length;
}
return unescape(document.cookie.substring(offset, endstr));
}
// primary function to retrieve cookie by name
function getCookie(name)
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while(i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
{
return getCookieVal(j);
}
i = document.cookie.indexOf(" ", i) + 1;
if(i === 0) {break;}
}
return;
}
// store cookie value with optional details as needed
function setCookie(name, value, expires, path, domain, secure)
{
document.cookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}
// remove the cookie by setting ancient expiration date
function deleteCookie(name,path,domain)
{
if(getCookie(name))
{
document.cookie = name + "=" +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}
function numberFormat(num,how)
{
num = Math.round(num*Math.pow(10,how))/Math.pow(10,how);
return num;
}
function countTotal()
{
var products = getCookie("shopcart");
var carts = products.split("|");
var total = 0;
for(var i=0;i < carts.length; i++)
{
var infos = carts[i].split(",");
alert($("price"+infos[0]));
var price = $F("price"+infos[0]);
if(price === null)
{
price =0;
}
total += eval(price)*eval(infos[3]);
}
alert(total);
return total;
}
function toCookieString(carts,idx)
{
var re = '';
for(var i = 0;i < carts.length; i++){
if(i!==idx)
{
re += carts[i];
re +='|';
}
}
return re;
}
//buy products action when user clicked 'buy' button
function buyProduct(pid,amt,cid)
{
if(pid==null){return;}
if(amt==null){amt=1;}
if(cid==null){cid=0;}
var cookiestr = getCookie("shopcart");
if(cookiestr==null||cookiestr=="")
{
cookiestr = "";
cookiestr = cookiestr.concat(pid+","+cid+","+amt);
}
else
{
cookiestr = saveProduct(pid,cookiestr,amt,cid);
}
setCookie("shopcart",cookiestr);
window.open("cart.htm","_blank");
return cookiestr;
}
function deleteProduct(pid,cid)
{
if(cid == null){cid = 0;}
var products = getCookie("shopcart");
var carts = products.split("|");
var idx = -1;
products="";
for(var i=0;i < carts.length; i++){
var infos = carts[i].split(",");
if(infos[0] == pid && infos[1] == cid)
{
idx = i;
}
else
{
products +=infos[0]+","+infos[1]+","+infos[2];
}
if(i!==(carts.length-1)&&(i!==idx))
{
products +="|";
}
if(i==(carts.length-1)&&(i==idx))
{
products = products.substr(0,products.length-1);
}
//alert(products);
//$("lbTotalPrice").
}
setCookie("shopcart",products);
$(""+pid).style.display = "none";
//return products;
}
function modifyProduct(pid,amt,cid)
{
if(cid == null){cid = 0;}
if(amt==null){amt=1;}
var products = getCookie("shopcart");
var carts = products.split("|");
products="";
for(var i=0;i < carts.length; i++){
var infos = carts[i].split(",");
if(infos[0] == pid && infos[1] == cid)
{
infos[2] = eval(amt);
}
products +=infos[0]+","+infos[1]+","+infos[2];
if(i!==(carts.length-1))
{
products +="|";
}
alert(products);
}
setCookie("shopcart",products);
//$(""+pid).style.display = "none";
//return products;
}
function saveProduct(pid,products,amt,cid)
{
if(cid==null){cid=0;}
if(amt==null){amt=1;}
var isFind = false;
var carts = products.split("|");
var i=0;
products="";
for(;i < carts.length; i++){
var infos = carts[i].split(",");
if(infos[0] == pid && infos[1] == cid)
{
infos[2] = eval(infos[2])+eval(amt);
isFind = true;
}
products +=infos[0]+","+infos[1]+","+infos[2];
if(i!==(carts.length-1))
{
products +="|";
}
}
if(!isFind)
{
products = products.concat("|"+pid+","+cid+","+amt);
}
return products;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -