开发者社区> 问答> 正文

jQuery 如何获取点击链接的查询参数?

例如有这么个链接:

Create Account

代码如下:

$('.dialogOnClick').live('click', function() {
    // How to get 640, given we look for the width param?
    console.log( $(this).?????)
});

我要获取640这个参数值,应该很简单的吧,可是我不会 :(

展开
收起
a123456678 2016-07-05 11:08:02 2100 0
1 条回答
写回答
取消 提交回答
  • function parseURL(url) {
     var a =  document.createElement('a');
     a.href = url;
     return {
     source: url,
     protocol: a.protocol.replace(':',''),
     host: a.hostname,
     port: a.port,
     query: a.search,
     params: (function(){
         var ret = {},
             seg = a.search.replace(/^\?/,'').split('&'),
             len = seg.length, i = 0, s;
         for (;i<len;i++) {
             if (!seg[i]) { continue; }
             s = seg[i].split('=');
             ret[s[0]] = s[1];
         }
         return ret;
     })(),
     file: (a.pathname.match(/\/([^\/?#]+)$/i) || [,''])[1],
     hash: a.hash.replace('#',''),
     path: a.pathname.replace(/^([^\/])/,'/$1'),
     relative: (a.href.match(/tps?:\/\/[^\/]+(.+)/) || [,''])[1],
     segments: a.pathname.replace(/^\//,'').split('/')
     };
    }
    2019-07-17 19:51:18
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关课程

更多

相关电子书

更多
JCLI使用说明文档 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载

相关实验场景

更多