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.
精彩评论