gpt4 book ai didi

javascript - onclick window.location.href 带输入值

转载 作者:可可西里 更新时间:2023-10-31 23:58:32 26 4
gpt4 key购买 nike

我有一个输入,我希望将用户发送到 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com