我有一个输入,我希望将用户发送到 URI 中包含输入值的另一个页面,以便我可以提取它。
我的输入是这样设置的:
<input name="date" id="datepicker" onchange="window.location.href = 'test.php?Date=' + document.getElementById("datepicker").value;">
基本上,当日期发生变化时,日期应该添加到 URI 的末尾,用户应该被发送到 test.php,其中值将被提取。但是,该值似乎没有添加。
有什么问题?
最佳答案
尝试:
<input name="date" id="datepicker" onchange="window.location.href = 'test.php?Date=' + this.value;">
您不需要执行 document.getElementById('datepicker')
因为您所在的元素已经是您想要从中获取值的元素。
关于javascript - onclick window.location.href 带输入值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21539427/