js 关闭页面
var browserName=navigator.appName;
if (browserName=="Netscape") {
window.open(‘‘,‘_parent‘,‘‘); window.close(); }
else if (browserName=="Microsoft Internet Explorer") {
window.opener = "whocares"; window.close(); }
Js 手机验证
<script>
var mobile = "";
var code = "";
function CheckMobile() {
mobile = $.trim($("#MobileNumber").val());
if (mobile.length == 0) {
alert(‘请输入手机号码‘)
return false;
} else if (!/1\d{10}/i.test(mobile)) {
alert(‘手机号码格式不正确‘)
return false;
}
return true;
}
function checkValidateCode() {
code = $.trim($("#CheckCode").val());
if (code.length == 0) {
alert(‘请输入验证码‘)
return false;
} else if (code.length != 6) {
alert(‘验证码位数不正确‘)
return false;
} else if (!/^(\d{6})$/i.test(code)) {
alert(‘验证码格式不正确‘)
return false;
}
return true;
}
jQuery(function () {
$("#btnSubmit").click(function () {
if (!CheckMobile())
return false;
if (!checkValidateCode())
return false;
$.post("@Url.Action("Bind", "Home")", { "MobileNumber": mobile, "CheckCode": code }, function (data) {
if (data.Result != undefined && data.Result != null && data.Result)
window.location.replace("/home/mybaby");
else
alert(data.Message);
});
});
$("#btnSendValidate").click(function () {
var $this = $(this);
var flag = CheckMobile();
if (!flag)
return false;
var timeless = 60;
$this.html("已发送(" + timeless + ")");
$this.attr("disabled", "disabled")
var t = setInterval(function () {
if (timeless > 1) {
timeless--;
$this.html("已发送(" + timeless + ")");
} else {
$this.html("获取验证码");
$this.removeAttr("disabled");
clearInterval(t);
}
}, 1000);
$.ajax({
url: "@Url.Action("SendCode","Home")", type: "POST", dataType: "json", contentType: "application/json;utf-8",
data: JSON.stringify({ MobileNumber: mobile }),
success: function (data) {
if (data.Message != undefined && data.Message != null) {
alert(data.Message);
}
},
error: function (err) {
alert(‘绑定异常‘)
}
});
return false;
});
});
</script>
3. js.ajax
$.ajax({ type: "Get", url: "/home/DropdownClass", dataType: "Json", success: function (data) { $.each(data, function (index, ele) { content += " <li tag=‘" + ele.Value + "‘ onclick=‘otherclass(this)‘>" + ele.Text + " 共(" + ele.Num + ")人 </li>" }); $("#dropdwonclass").html(content); } });
4. js.跳转
js方式的页面跳转 1.window.location.href方式 <script language="javascript" type="text/javascript"> window.location.href="target.aspx"; </script> 2.window.navigate方式跳转 <script language="javascript"> window.navigate("target.aspx"); </script> 3.window.loction.replace方式实现页面跳转,注意跟第一种方式的区别 <script language="javascript"> window.location.replace("target.aspx"); </script> 有3个jsp页面(1.aspx, 2.aspx, 3.aspx),进系统默认的是1.aspx,当我进入2.aspx的时候, 2.aspx里面用window.location.replace("3.aspx"); 与用window.location.href ("3.aspx"); 从用户界面来看是没有什么区别的,但是当3.aspx页面有一个"返回"按钮,调用window.history.go(-1); wondow.history.back();方法的时候,一点这个返回按钮就要返回2.aspx页面的话,区别就出来了,当用 window.location.replace("3.aspx");连到3.aspx页面的话,3.aspx页面中的调用 window.history.go(-1);wondow.history.back();方法是不好用的,会返回到1.aspx。 4.self.location方式实现页面跳转,和下面的top.location有小小区别 <script language="JavaScript"> self.location=‘target.aspx‘; </script> 5.top.location <script language="javascript"> top.location=‘target.aspx‘; </script> 6.不推荐这种方式跳转 <script language="javascript"> alert("返回"); window.history.back(-1); </script> meta方式实现跳转(content = 3 单位是秒) <meta http-equiv=refresh content=3;URL="http://www.dayanmei.com">
原文:http://www.cnblogs.com/29boke/p/5405830.html