How do I put a javascript variable inside the url?
This question already has an answer here:
Parameters in the query string are not automatically passed to Javascript; they're usually meant for server-side scripts. To get one variable you could do this:
var m = location.href.match(/[?&]variable=([^&]*)/),
password;
if (m) {
password = m[1];
}
you can pass variable like this:
<script language="javascript" type="text/javascript">
var scrt_var = 10;
</script>
<a href="2.html" onclick="location.href=this.href+'?key='+scrt_var;return false;">Link</a>
or like this:
put id attribute on anchor element
<a id="link2">
set href attribute on page load event:
var scrt_var = 10;
var strLink = "2.html&Key=" + scrt_var;
document.getElementById("link2").setAttribute("href",strLink);
链接地址: http://www.djcxy.com/p/17618.html
上一篇: 在文件加载时,GET数据被扔进页面