获取调用JS链接所带的参数

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>

</body>
 <script src="Content/lib/jquery/1.9.1/jquery.min.js"></script> 
<!--<script  id="test" type="text/javascript" src="Content/interface.js?id=666"></script>-->
<script id="test" type="text/javascript" src="Content/interface.js?id=49&name=doll.net" ></script>
</html>

//在页面引入interface.js后面带参数id=49和name=doll.net;
// 要在 interface.js 获取所带的 49和 doll.net
js里面这样写:
function tes(paramName)   
{   
    var reg = new RegExp("(^|/?|&)"+ paramName+"=([^&]*)(/s|&|$)", "i");
  
    if (reg.test(test.src)) //test为script ID 
        return RegExp.$2; 
    else
        return ""; 
}
调用 alert(test("id"));alert(test("name"))
弹出值 1  和 doll.net




文章转载至:http://blog.csdn.net/lanlandechong/article/details/1768272#comments


发布了14 篇原创文章 · 获赞 32 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/qq_34897745/article/details/77971249