Start page to pass the value of js. If you are free to study _ javascript skills

Source: Internet
Author: User
The page at the starting point transmits the value js. If you have time to study it The Code is as follows:


Script
Function ChangeParam (name, value ){
Var url = window. location. href;
Var newUrl = "";
Var reg = new RegExp ("(^ |)" + name + "= ([^ &] *) (| $ )");
Var tmp = name + "=" + value;
If (url. match (reg )! = Null ){
NewUrl = url. replace (eval (reg), tmp );
}
Else {
If (url. match ("[\?] ")){
NewUrl = url + "&" + tmp;
}
Else {
NewUrl = url + "? "+ Tmp;
}
}
// If the category is changed, it starts from page 1st
If (name! = "PageIndex "){
Reg = new RegExp ("(^ |) PageIndex = ([^ &] *) (| $ )");
Tmp = "PageIndex = 1 ";
If (newUrl. match (reg )! = Null ){
NewUrl = newUrl. replace (eval (reg), tmp );
}
}
Location. href = newUrl;
}
Function QueryMonthTicket ()
{
If ($ ("selectM ")! = Null & $ ("selectY ")! = Null)
{
Var month = $ ("selectY"). value + $ ("selectM"). value;
ChangeParam ("Month", month );
}
}

Function GoPage ()
{
Var page = $ ("txtPage"). value. trim ();
If (page. length = 0 ){
Alert ("Enter the page number ");
Return false;
};
Var strNum = '000000 ';
Var isNum = true;
For (var I = 0; I Var c = page. charAt (I );
If (strNum. indexOf (c) <0 ){
IsNum = false;
Break;
};
};
If (isNum ){
If (parseInt (page)> parseInt (initTotalPage )){
Alert ("the number of pages you entered exceeds the total number of pages. Please try again! ");
Return false;
};
ChangeParam ("PageIndex", page );
} Else alert ('the information you entered is incorrect. Please try again! ');
}

Function GoEnter (evt ){
Evt = evt | window. event;
If (evt & evt. keyCode = 13) return GoPage ();
};
Script

Related Article

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.