开发者

read parameter on js file [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Pass vars to JavaScript via the SRC attribute

May I know how to read get the p value on j开发者_如何学Cs file link like filename.js?p=value with local javascript in the js file? Any function to work like the $_GET['p'] in php? Thanks.


try this:

var tmp = location.href, it;
if (q) it = tmp.substr(q + 1).split('&');
else it = '';
for (var i in it) {
    var t = it[i].split('=');
    if (t[0] == 'p') {
        //do something
        break;
    }
}


function _GET( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

This will do the equivalent in javascript.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜