我有2页。第一页有一个Javascript函数,它获取h1的值,当用户单击该按钮时,警报将显示值为h1,它将重定向到另一个页面。第二页有一个HTML表单。
现在我想从第1页调用js函数并在输入文本(第2页)中显示值。
我尝试了这个<?php echo "<script>document.writeln(h1function);</script>"; ?>
,但它无法正常工作。
这是js脚本:
function h1function(){
var h1 = document.getElementsByClassName("entry-title");
for(var i = 0; i < h1.length; i++){
alert(h1[i].innerHTML);
}
}
第1页:
<a href="http://example.com/list/summary/" target="_blank" onclick="h1function()">
HTML(第2页):
<input type="text" name="h1title" value="<?php echo "<script>document.writeln(getJob);</script>"; ?>" size="40" id="h1title" required/>
答案 0 :(得分:0)
您可以使用:
HTML5存储,如here
答案 1 :(得分:0)
您可以使用GET
function h1function(){
window.location.href = "http://example.com/page2?&h1="+h1[i].innerHTML;
}
HTML第2页
<input type="text" name="h1title" value="<?php echo $_GET['h1']" size="40" id="h1title" required/>