Javascript window.location使用按钮onclick截断URL

Javascript window.location使用按钮onclick截断URL,javascript,html,button,onclick,window.location,Javascript,Html,Button,Onclick,Window.location,使用按钮onclick事件设置window.location时,结果将在第二个参数名称后被截断 此代码: <button onclick="window.location='index.php?p=reports_manage&id=new'">create new report - button</button> 即使我在末尾添加了额外的参数,它仍然在同一个位置被切断 但是,所有这些都很好: <a href="index.php?p=reports_ma

使用按钮onclick事件设置window.location时,结果将在第二个参数名称后被截断

此代码:

<button onclick="window.location='index.php?p=reports_manage&id=new'">create new report - button</button>
即使我在末尾添加了额外的参数,它仍然在同一个位置被切断

但是,所有这些都很好:

<a href="index.php?p=reports_manage&id=new">create new report - link</a>
<a href="javascript:window.location='index.php?p=reports_manage&id=new'">create new report - JS1</a>
<a href="javascript:void(0);" onclick="window.location='index.php?p=reports_manage&id=new'">create new report - JS2</a>


你知道这是什么原因吗?据我所知,按钮在之前工作正常,并且在代码没有任何更改的情况下坏了。还有什么会影响这一点?页面上没有javascript错误,无论使用何种浏览器,都会发生这种情况。

使用
而不是
,因为它有意外的行为(如果用于提交表单,它甚至会提交其内容!)

很可能,但指定按钮类型可能会有所帮助。在这种情况下,type=“button”


@不同的浏览器有不同的先决条件,但是作为一种保护措施,显式的总是好的

DOM检查器是否显示与HTML代码相同,或者可能存在解析问题?您是否尝试使用而不是button元素?我建议始终使用input for button,因为浏览器对@Bergi有不同的、有时是意外的行为,DOM检查器确实显示了正确的代码。然而,当我将鼠标悬停在IE中的按钮上时,它会在页面底部显示截断的url。我将仔细查看所有其他内容,以查找语法错误或开放引号。@gillesc使用输入标记在这里非常有效。不知道为什么没有,但这不太重要。你能把它作为一个解决方案输入,这样我就可以信任你了吗?谢谢。我最初使用它是因为页面上已经有一个表单,我根本不想让它们混在一起,但这似乎不是问题。使用@trickyzter的答案中的
也可以。
<a href="index.php?p=reports_manage&id=new">create new report - link</a>
<a href="javascript:window.location='index.php?p=reports_manage&id=new'">create new report - JS1</a>
<a href="javascript:void(0);" onclick="window.location='index.php?p=reports_manage&id=new'">create new report - JS2</a>