繁体   English   中英

如何将一个页面的文本框值传递到另一个页面的文本框?

[英]How to pass textbox value from a page into a textbox in another page?

我尝试将文本框值从一个页面传递到另一个页面。 我尝试通过该文本框,但是我使用JavaScript失败了。 我必须尝试正确更改代码,但仍然无法正常工作,错误是传递给文本框的数据是多个。

这是我的代码第一页代码

  function myFunction() { var inputTest = document.getElementById('tanggal2').value; var inputTest1 = document.getElementById('dt').value; localStorage.setItem( 'objectToPass', inputTest ); localStorage.setItem( 'objectToPass1', inputTest1 ); if (inputTest=="") { window.open('report_pengambilan_singgle.html','','height=650,width=1200'); } else { window.open('report_pengambilan_singgle1.html','','height=650,width=1200'); } } 
 <input type="text" id="dt" type="text" name="dt" maxlength="1" size="23" readonly="readonly" style="visibility:hidden" /> <input type="text" id="tanggal2" type="text" name="tanggal2" maxlength="1" size="23" readonly="readonly" style="visibility:hidden" /> <label onclick="myFunction();" >a</label> 

这是我的第二页代码

  var inputTest = localStorage.getItem('objectToPass'); var inputTest1 = localStorage.getItem('objectToPass1'); var displayData = inputTest; var displayData = inputTest1; document.getElementById("datepicker1").value=inputTest; document.getElementById("datepicker2").value=inputTest; document.getElementById("datepicker3").value=inputTest; localStorage.removeItem( 'objectToPass1' ); // Clear the localStorage localStorage.removeItem( 'objectToPass' ); // Clear the localStorage 

您有隐藏的textbox ,没有任何值定义

因此,首先在<script>开始之前在textbox设置任何值,然后在另一个页面中创建textbox

喜欢

<input type="text" id="datepicker1" value="">
<input type="text" id="datepicker2" value="">
<input type="text" id="datepicker3" value="">

试试这个...

的test.html

<script>function myFunction() {

var inputTest = document.getElementById('tanggal2').value;
var inputTest1 = document.getElementById('dt').value;

if (inputTest=="") {
                    window.open('report_pengambilan_singgle.html','','height=650,width=1200');
            }   
            else {

                    window.open('test1.html?name=' + inputTest1,'','height=650,width=1200');
            }

}
</script>
<input type="text" id="dt" type="text" name="dt"  size="23"  />
<input type="text" id="tanggal2" type="text" name="tanggal2"  size="23"  />
<button onclick="myFunction();" >a</button> 

test1.html

<script>window.onload = function () {
var url = document.location.href,
    params = url.split('?')[1].split('&'),
    data = {}, tmp;
for (var i = 0, l = params.length; i < l; i++) {
     tmp = params[i].split('=');
     data[tmp[0]] = tmp[1];
}
document.getElementById("datepicker1").value = data.name;
}
</script>
<input type="text" id="datepicker1" type="text" name="datepicker1"  size="23"  />

我希望为你工作...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM