如何将html中的值传递给js
1个回答
2016-12-24
展开全部
JS方式实现静态页之间值传递,参考如下:
在body标签之间加此行代码:
<form action=”a.html?d1=123&d2=你好” method=”post” name=”f1″ id=”f1″>
<input type=”submit” name=”s1″ id=”s1″ value=”提交”/>
</form>
然后,新建a.html新页,同样在body标签之间加此行代码,如下:
<script type=”text/javascript”>
var tmpArr;
var QueryString;
var URL = document.location.toString();
if(URL.lastIndexOf(“?”)!=-1){
QueryString= URL.substring(URL.lastIndexOf(“?”)+1,URL.length);
tmpArr=QueryString.split(“&”);
for (i=0;i<=tmpArr.length – 1;i++) {
document.write(“参数为:” + tmpArr[i] + “<br/>”);
}
}
else{
QueryString = “”;
}
</script>
在body标签之间加此行代码:
<form action=”a.html?d1=123&d2=你好” method=”post” name=”f1″ id=”f1″>
<input type=”submit” name=”s1″ id=”s1″ value=”提交”/>
</form>
然后,新建a.html新页,同样在body标签之间加此行代码,如下:
<script type=”text/javascript”>
var tmpArr;
var QueryString;
var URL = document.location.toString();
if(URL.lastIndexOf(“?”)!=-1){
QueryString= URL.substring(URL.lastIndexOf(“?”)+1,URL.length);
tmpArr=QueryString.split(“&”);
for (i=0;i<=tmpArr.length – 1;i++) {
document.write(“参数为:” + tmpArr[i] + “<br/>”);
}
}
else{
QueryString = “”;
}
</script>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询