我希望通过点击按钮获得重定向,我使用:
<inputtype="submit" onclick="location.href='first';" value="goSomewhere1"/>
<inputtype="submit" onclick="location.href='second';" value="goSomewhere2"/>
如果在页面http://ADDRESS
上点击它就会工作,但如果在url
与http://ADDRESS/something
类似时点击它,则会重定向到http://ADDRESS/something/first
如何才能在ADDRESS
之前获得重定向,但不能将此值(ADDRESS
)放在一起,因为它可能会发生变化? (对于此示例,它应该http://ADRESS/first
} http://ADDRESS/something/first
} {/ 1>}
答案 0 :(得分:1)
您希望/first
不是first
。
没有斜线,它是一个相对链接。使用斜杠,它对于基本URL是绝对的。
<input type="submit" onclick="location.href='/first'" value="goSomewhere1"/>
<input type="submit" onclick="location.href='/second'" value="goSomewhere2"/>