使用javascript将参数传递到下一页

时间:2017-04-04 10:36:33

标签: javascript

javascript将会生成一些照片和照片描述。 我需要点击照片,然后它会将参数(标题)发送到下一页,所以让下一页生成关于我点击的照片的信息

这是我的代码,我尝试使用document.submit()来做,但似乎失败了。

在第一页:

function print(){
  var detail = getVideo();
  var number = detail.length;
   document.getElementById("watch").innerHTML = "";
  for (i=0;i<=number;i++){
  document.getElementById("watch").innerHTML += ('<a href="play.html" onclick="submitvideo(detail[i].title)"><img src='+detail[i].poster+'></a>');
  document.getElementById("watch").innerHTML += ('<h class="vname">'+detail[i].title+'</h>')
  document.getElementById("watch").innerHTML += ('<p>'+detail[i].desc+'</p>');
}


function submitvideo(title){
  title.submit();
}

在第二页:(现在只是用来测试它是否通过)

<script type="text/javascript">
function getv(){
  alert(document.location.search);

}
</script>

3 个答案:

答案 0 :(得分:0)

将href用作参数持有者f._2._2 / f._2._1

href="play.html?title='+detail[i].title+'"

function print(){ var detail = getVideo(); var number = detail.length; document.getElementById("watch").innerHTML = ""; for (i=0;i<=number;i++){ document.getElementById("watch").innerHTML += ('<a href="play.html?title='+detail[i].title+'"><img src='+detail[i].poster+'></a>'); document.getElementById("watch").innerHTML += ('<h class="vname">'+detail[i].title+'</h>') document.getElementById("watch").innerHTML += ('<p>'+detail[i].desc+'</p>'); } 中,您可以拆分链接并获取play.html

photoTitle

答案 1 :(得分:0)

像这样改变您的代码

document.getElementById("watch").innerHTML += ('<a href="play.html?title='+detail[i].title+'"><img src='+detail[i].poster+'></a>');

答案 2 :(得分:0)

如果这些网页来自同一个网域,协议可以Local Storage为您提供帮助吗?