gpt4 book ai didi

javascript - Html 按钮不会重定向到链接

转载 作者:行者123 更新时间:2023-11-30 12:41:23 25 4
gpt4 key购买 nike

我正在尝试在 html 上创建一个按钮,当我按下它时它会被重定向到 http://example.com/mysite/?rand=1

到目前为止我尝试的是:

<form action="http://example.com/mysite/?rand=1">
<div class="checkboxes" align="center">
<input placeholder="TextArea" style="width: 296px; height: 30px;" type="text" autocomplete="off">
<label for="x"><input type="checkbox" id="x" checked/><span> Just a checkbox 1 </span></label>
<label for="y"><input type="checkbox" id="y" disabled/><span> Just a checkbox 2 </span></label>
<button id="Button" type="submit">Press me</button>
</form>

我只被重定向到 http://example.com/mysite/

我也试过像这样使用 javascript:

<script "text/javascript">
document.getElementById("Button").onclick = function () {
location.href = "http://example.com/mysite/?rand=1";
};
</script>

<form>
<div class="checkboxes" align="center">
<input placeholder="TextArea" style="width: 296px; height: 30px;" type="text" autocomplete="off">
<label for="x"><input type="checkbox" id="x" checked/><span> Just a checkbox 1 </span></label>
<label for="y"><input type="checkbox" id="y" disabled/><span> Just a checkbox 2 </span></label>
<button id="Button">Press me</button>
</form>

结果是一样的,我被重定向到http://example.com/mysite/

如果我使用其他链接进行重定向,如 google.com 等,重定向工作正常,但不适用于我实际站点的链接。如果我在另一个选项卡中打开链接,这些链接就可以正常工作

我不确定如何调试它,有人知道问题出在哪里吗?

最佳答案

你的html不正确

这是改正后的

<form action="http://example.com/mysite/?rand=1">
<div class="checkboxes" align="center">
<input placeholder="TextArea" style="width: 296px; height: 30px;" type="text" autocomplete="off" />
<label for="x">
<input type="checkbox" id="x" checked="checked" /><span> Just a checkbox 1 </span>

</label>
<label for="y">
<input type="checkbox" id="y" disabled="disabled" /><span> Just a checkbox 2 </span>

</label>
<button id="Button" type="submit">Press me</button>
</div>
</form>

Demo Fiddle

关于javascript - Html 按钮不会重定向到链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24320351/

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