(1)获得URL参数
function GetQueryString("url参数名") {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return (r[2]);
return null;
}
(2)获得url 中文参数转码
decodeURI(GetQueryString("url参数名"))
(3)滑动到底部产生事件
$(window).scroll(function() {
if ($(window).scrollTop() + $(window).height() == $(document).height()) {
}
});
(4)价格保留两位小数
(价格).toFixed(2)
(5)延迟执行事件
window.setTimeout(function () {
window.location.href = ‘www.cnblogs.com/huangenai/‘;
}, 2500);
(6)点击事件
$(document).on(‘touchstart click‘, ".profile_li",function(e) {
e.preventDefault();
});
(7)ajax请求数据
$(‘#btnOK‘).click(function () {
$.ajax({
type: "POST",
url: ‘/Home/index‘,
data: { }, //参数
datatype: "html",
success: function (data) {
},
error: function () {
}
});
});
(8)获得验证码倒计时效果
<input id="btn" value="获取验证码"/>
var wait = 60;
document.getElementById("btn").disabled = false;
function time(o) {
if (wait == 0) {
o.removeAttribute("disabled");
o.value = "获取验证码";
wait = 60;
} else {
o.setAttribute("disabled", true);
o.value = "重新发送(" + wait + ")";
wait--;
setTimeout(function() {
time(o);
},
1000);
}
}