Javascript Html按钮没有';不要重定向到链接
我试图在html上创建一个按钮,当我按下它时,它会被重定向到 到目前为止,我尝试的是:Javascript Html按钮没有';不要重定向到链接,javascript,html,Javascript,Html,我试图在html上创建一个按钮,当我按下它时,它会被重定向到 到目前为止,我尝试的是: <form action="http://example.com/mysite/?rand=1"> <div class="checkboxes" align="center"> <input placeholder="TextArea" style="width: 296px; height: 30px;" type="text" autocomplet
<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>
只是一个复选框1
只是一个复选框2
按我
我只重定向到
我还尝试了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>
document.getElementById(“按钮”).onclick=function(){
location.href=”http://example.com/mysite/?rand=1";
};
只是一个复选框1
只是一个复选框2
按我
结果是一样的,我被重定向到
如果我使用其他链接重定向,比如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>
只是一个复选框1
只是一个复选框2
按我
您的
元素需要名称
属性。name
是在查询字符串中结束的参数,而id
用于DOM操作和CSS。
使用隐藏的
添加rand
参数:
<input type="hidden" name=rand" value="1">
<input placeholder="TextArea" name="text" style="width: 296px; height: 30px;" type="text" autocomplete="off">
<label for="x"><input type="checkbox" name="x" id="x" checked/><span> Just a checkbox 1 </span></label>
<label for="y"><input type="checkbox" name="y" id="y" disabled/><span> Just a checkbox 2 </span></label>
如果您正在使用URL重写,则其URL重写问题…请检查..其重定向到正确的地址…但URL重写会截断您的查询字符串。@K.K.Agarwal我不确定我是否理解,但如果我打开的工作正常..@Stefan,关闭divmissing@captainsac没什么,我只是想试试,然后我把它放在那里了