Summarize some common frontend JQ operations (improved slowly) and frontend jq

Source: Internet
Author: User

Summarize some common frontend JQ operations (improved slowly) and frontend jq

1. instantiate a Js object and use it as a class. The example is a url parameter.

Function GetRequestCondition () {var url = window. location. href; var conditon = url. substring (url. indexOf ("? ") + 1, url. length); var strs = conditon. split ("&"); var theRequest = new Object (); for (var I = 0; I <strs. length; I ++) {theRequest [strs [I]. split ("=") [0] = decodeURI (strs [I]. split ("=") [1]); // you must use the decodeURI () function to decode the URI encoded by the encodeURI () function. } Return theRequest;} var Request = new Object (); Request = GetRequestCondition (); $ ("# OrderID "). val (Request ["OrderID"]); $ ("# TraderName "). val (Request ["TraderName"]); $ ("# MallName "). val (Request ["MallName"]); $ ("# Contacts "). val (Request ["Contacts"]);

2. Method for replacing the value of the specified parameter in the URL

  function replaceParamVal(oldUrl, paramName, value) {            var reg = eval('/(' + paramName + '=)([^&]*)/gi');            var newUrl = oldUrl.replace(reg, paramName + '=' + value);return newUrl;        }

 

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.