带输入值的onclick window.location.href

use*_*282 3 javascript php jquery onchange window.location

我有一个输入,我希望用户被发送到另一个页面,其中包含URI中的输入值,以便我可以提取它.

这是我的输入设置方式:

<input name="date" id="datepicker" onchange="window.location.href = 'test.php?Date=' + document.getElementById("datepicker").value;">
Run Code Online (Sandbox Code Playgroud)

基本上,当更改日期时,应将日期添加到URI的末尾,并且应将用户发送到test.php,其中将提取值.但是,似乎没有添加该值.

有什么问题?

put*_*nde 10

尝试:

<input name="date" id="datepicker" onchange="window.location.href = 'test.php?Date=' + this.value;">
Run Code Online (Sandbox Code Playgroud)

您不需要这样做,document.getElementById('datepicker')因为您所在的元素已经是您想要的值.