jQuery从它自己的(自己)链接获取查询字符串 [英] jQuery get query string from it's own (self) link

查看:109
本文介绍了jQuery从它自己的(自己)链接获取查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以有这样的javascript链接(注意查询字符串):

Is it possible to have a javascript link like this (notice the query string):

  <script type = "text/javascript" src = "/js/myScipt.js?v=3"></script>

然后在myScript.js中使用jQuery获取v的值?一个javascript的答案也可以,但jQuery是首选。提前致谢!我搜遍了所有我能找到的有关在URL中获取查询字符串值的问题,但不是来自它自己的链接。

and then in myScript.js get the value of v using jQuery? A javascript answer is okay too, but jQuery is preferred. Thanks in advance! I searched all over and all I could find were questions pertaining to getting the value of a query string in the URL, but not from it's own link.

推荐答案

//to set script do some thing like this
var version = 3;
document.write('<script type = "text/javascript" src = "/js/myScipt.js?v='+version+'"></script>');
//or 
$("body").append('<script type = "text/javascript" src = "/js/myScipt.js?v='+version+'"></script>');


//to get v from myscript.js
var getV = document.currentScript.src.split("?v=")[1];
// var getV =  $('script').last().attr("src").split("?v=")[1];

这篇关于jQuery从它自己的(自己)链接获取查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆