我需要将page1.html中的值传递给page2.html。但是,打开page2.html并填写输入字段时没有任何反应。
我该如何解决?
Page1.html
<body>
<div class="pname" data-id="barcode-number" onclick="goforward(this);">Prod</div>
<script type="text/javascript">
function goforward(d) {
var r = d.getAttribute("data-id");
var detailsWindow = window.open('page2.html');
detailsWindow.onload = function{
document.getElementById('prod0').value = p1name;
document.getElementById('prod1').value = p2name;
}
}
</script>
</body>
Page2.html
<!DOCTYPE html>
<html><head><title></title></head>
<body>
<div class="md_product">
<input id="prod0" value="Product One">
<input id="prod1" value="Product Two">
</div>
</body></html>
答案 0 :(得分:0)
您可以使用JS localstorage来满足您的要求。 这是一个可以解决您问题的案例。
第1页:
<body>
<div class="pname" data-id="barcode-number" onclick="goforward(this);">Prod</div>
<script type="text/javascript">
function goforward(d) {
var r = d.getAttribute("data-id");
var detailsWindow = window.open('page2.html');
detailsWindow.onload = function{
let val1 = document.getElementById('prod0').value = p1name;
localStorage.setItem('prod0', 'val1');
let val2 = document.getElementById('prod1').value = p2name;
localStorage.setItem('prod1', 'val2');
}
}
</script>
</body>
第2页:
<!DOCTYPE html>
<html><head><title></title></head>
<body>
<div class="md_product">
<input id="prod0" value="Product One">
<input id="prod1" value="Product Two">
</div>
</body>
<script type="text/javascript">
var prod0 = localStorage.getItem("prod0");
var prod1 = localStorage.getItem("prod1");
document.getElementById('prod0').value=prod0;
document.getElementById('prod1').value=prod1;
</script>
</html>
答案 1 :(得分:0)
你必须像/ page2那样在渲染网址中传递参数吗?param1 = textbox1value,param2 = textbox2value