common.js
ylbtech-JavaScript-util:common.js |
通用方法
1.A,JS-效果图返回顶部 |
1.B,JS-Source Code(源代码)返回顶部 |
1.B.1, m.yintai
View Code
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
/* 返回 */ function goback() { var returnUrl = $.query.get("returnUrl"); if (returnUrl != "null" && returnUrl != "") { window.location.href = returnUrl; } else { window.history.go(-1); } } /* 跳转 */ function redirectAction(actionType, arguments) { var args = getJsonArgs(arguments); if (actionType == "1") { window.location.href = "/Sales/ProductList?searchCondition=" + encodeURI(args.searchcondition) + "&title=" + encodeURI(args.titlecontent); } else if (actionType == "2") { window.location.href = "/Sales/ProductDetail?itemCode=" + args.itemcode; } else if (actionType == "3") { alert(actionType + "|" + arguments); } else if (actionType == "4") { window.location.href = "/Sales/CustomProductList?param=" + args.param + "&title=" + encodeURI(args.titlecontent); } else if (actionType == "5") { if (args.id == "0") { window.location.href = "/LimitBuy"; } else { window.location.href = "/LimitBuy/ProductList?bargainid=" + args.bargainid + "&title=" + encodeURI(args.titlecontent); } } else if (actionType == "18") { window.location.href = args.weburl; } else if (actionType == "19") { window.location.href = args.weburl; } else { alert("不支持的跳转类型" + actionType + "|" + arguments); } } function getJsonArgs(arguments) { if (arguments == null || arguments == undefined || arguments == "") { return {}; } var arrArguments = arguments.split("|"); var i = 0; var strJsonArguments = "{"; while (i < arrArguments.length) { if (i > 0) { strJsonArguments += ","; } var index = arrArguments[i].indexOf(":"); var name = arrArguments[i].substring(0, index); var value = arrArguments[i].substring(index + 1); strJsonArguments += name + ":'" + value + "'"; i++; } strJsonArguments += "}"; var args = eval("(" + strJsonArguments + ")"); return args; } /* 输出价格 */ function outputPrice(containerID, strPrice) { var price = parseFloat(strPrice); $("#" + containerID).html(price.toFixed(2)); } /* 输出文本 */ function outputText(containerID, text) { $("#" + containerID).html(text); } /* 取得选中的名称 */ function getSelectedText(controlID) { var selectedText = null; $("#" + controlID + " option").each(function () { if ($(this).attr("selected")) { selectedText = $(this).text(); return false; } }); return selectedText; } /* 格式化金额 */ function formatAmount(strAmount) { var fAmount = parseFloat(strAmount); return fAmount.toFixed(2); } /* 取得元素绝对位置 */ function getElementAbsPos(e) { var t = e.offsetTop; var l = e.offsetLeft; while (e = e.offsetParent) { t += e.offsetTop; l += e.offsetLeft; } return { left: l, top: t }; } /* 在线支付 */ function pay(outTradeNo, totalFee, subject) { var data = new Object(); //订单号 data.out_trade_no = outTradeNo; //金额 data.total_fee = totalFee; data.subject = subject; url = "/Services/PayOnline.ashx?r=" + Math.random(); $.ajax({ url: url, dataType: "html", data: data, success: function (result) { document.write(result); }, error: function (xmlHttpRequest, textStatus, errorThrown) { alert(errorThrown); } }); } /* 取得客户端操作系统 */ function getOs() { var navigator = window.navigator, userAgent = navigator.userAgent, android = userAgent.match(/(Android)[\s\/]+([\d\.]+)/), ios = userAgent.match(/(iPad|iPhone|iPod)\s+OS\s([\d_\.]+)/), wp = userAgent.match(/(Windows\s+Phone)\s([\d\.]+)/), isWebkit = /WebKit\/[\d.]+/i.test(userAgent), isSafari = ios ? (navigator.standalone ? isWebkit : (/Safari/i.test(userAgent) && !/CriOS/i.test(userAgent) && !/MQQBrowser/i.test(userAgent))) : false, os = {}; if (android) { os.android = true; os.version = android[2]; } if (ios) { os.ios = true; os.version = ios[2].replace(/_/g, '.'); os.ios7 = /^7/.test(os.version); if (ios[1] === 'iPad') { os.ipad = true; } else if (ios[1] === 'iPhone') { os.iphone = true; os.iphone5 = window.screen.height == 568; } else if (ios[1] === 'iPod') { os.ipod = true; } } if (wp) { os.wp = true; os.version = wp[2]; os.wp8 = /^8/.test(os.version); } return os; } function search(keyword) { if (keyword == "") { alert("请输入要搜索的内容"); return; } if (keyword.length == 11) { window.location.href = "/Sales/ProductDetail?itemCode=" + keyword; } else { window.location.href = "/Sales/ProductList?keyword=" + keyword; } } /* 下载客户端 */ function downloadClient() { window.location.href = "/Home/Download"; } /* 转到顶部 */ function goTop() { $("html,body").animate({ scrollTop: 0 }, 1000); } /* 重置结算中心 */ function resetSettlement() { localStorage.removeItem("promotionCode"); localStorage.removeItem("discountType"); localStorage.removeItem("reduceID"); }
1.B.2,
1.C,JS-Relevent References(相关引用)返回顶部 |
![]() |
作者:ylbtech 出处:http://ylbtech.cnblogs.com/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 |