Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

9、URL 参数解析实现 #9

Open
shengq666 opened this issue Jun 28, 2020 · 1 comment
Open

9、URL 参数解析实现 #9

shengq666 opened this issue Jun 28, 2020 · 1 comment

Comments

@shengq666
Copy link
Owner

No description provided.

@shengq666
Copy link
Owner Author

例如一个url 为 http://www.runoob.com/index.php?id=1&image=awesome.jpg ,问号后面为 url 参数,其中多个参数时候会 使用 & 符号

function getQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++) {
        var pair = vars[i].split("=");
        if(pair[0] == variable){  return pair[1];  }
    }
       return(false);
}
getQueryVariable("id") 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant