Recently accumulated JS things, share a bit

Source: Internet
Author: User

JS Close page

var browsername=navigator.appname;     if (browsername== "Netscape") {window.open (', ' _parent ', '); Window.close ();}     

  

Js Phone Verification
<script>varMobile =""; varCode =""; function Checkmobile () {Mobile= $.trim ($ ("#MobileNumber"). Val ()); if(Mobile.length = =0) {alert ('Please enter your mobile phone number')            return false; } Else if(!/1\d{Ten}/i.test (MOBILE)) {Alert ('cell phone number format is not correct')            return false; }        return true; } function Checkvalidatecode () {Code= $.trim ($ ("#CheckCode"). Val ()); if(Code.length = =0) {alert ('Please enter a verification code')            return false; } Else if(Code.length! =6) {alert ('Verify that the number of code bits is incorrect')            return false; } Else if(!/^ (\d{6})$/i.test (code)) {Alert ('The captcha format is incorrect')            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"); Elsealert (data.            Message);        });        }); $("#btnSendValidate"). Click (function () {var$ This= $( This); varFlag =Checkmobile (); if(!flag)return false; varTimeless = -; $ This. HTML ("sent ("+ Timeless +")"); $ This. attr ("Disabled","Disabled")            vart =setinterval (function () {if(Timeless >1) {Timeless--; $ This. HTML ("sent ("+ Timeless +")"); } Else {                    $ This. HTML ("Get Verification Code"); $ This. Removeattr ("Disabled");                Clearinterval (t); }            },  +); $.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 ('Binding Exception')                }            }); 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 +"Total ("+ Ele. Num +") People </li>"                    }); $("#dropdwonclass"). HTML (content); }            });

4. js. Jump

JS Way of page Jump1. Window.location.href Mode<script language="JavaScript"Type="Text/javascript">window.location.href="target.aspx"; </script>2. Window.navigate Way to jump<script language="JavaScript">Window.navigate ("target.aspx");</script>3. Window.loction.replace way to achieve page jump, note the difference from the first way<script language="JavaScript">Window.location.replace ("target.aspx");</script>there are 3 JSP pages (1. aspx,2. aspx,3. aspx), into the system default is 1.aspx, when I enter 2.aspx,2. aspx inside with Window.location.replace ("3.aspx"); With the use of Window.location.href ("3.aspx"), there is no difference from the user interface, but when the 3.aspx page has a"return"button, call Window.history.go (-1); Wondow.history.back () method, a little bit of this return button will return to the 2.aspx page, the difference is out, when using Window.location.replace ("3.aspx"), to the 3.aspx page,3The. aspx page calls Window.history.go (-1); Wondow.history.back (); The method is not good and will return to 1.aspx. 4Self.location Way to implement the page jump, and the following top.location have a small difference<script language="JavaScript">self.location='target.aspx'; </script>5. Top.location<script language="JavaScript">top.location='target.aspx'; </script>6. This method is not recommended to jump<script language="JavaScript">Alert ("return"); Window.history.back (-1); </script>meta-mode implementation jumps (content=3Unit is seconds)<meta Http-equiv=refresh content=3; Url="http://www.dayanmei.com">

Recently accumulated JS things, share a bit

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.