我一直在尝试以下方法:
<form action="/home" class="inline">
<button class="float-left submit-button" >Home</button>
</form>
它似乎工作,但它去了页面“/home?”
有没有更好的方法让我在一个窗体内的按钮,使页面到一个新的位置?
我一直在尝试以下方法:
<form action="/home" class="inline">
<button class="float-left submit-button" >Home</button>
</form>
它似乎工作,但它去了页面“/home?”
有没有更好的方法让我在一个窗体内的按钮,使页面到一个新的位置?
只需添加一个onclick事件到按钮:
<button onclick="location.href = 'www.yoursite.com';" id="myButton" class="float-left submit-button" >Home</button>
但你不应该让它像那样内联,而是把它放在JS块中,并给按钮一个ID:
<button id="myButton" class="float-left submit-button" >Home</button>
<script type="text/javascript">
document.getElementById("myButton").onclick = function () {
location.href = "www.yoursite.com";
};
</script>
你可以这样做:
<button onclick="location.href='page'">
你可以在点击按钮时更改表单的动作属性:
<button class="float-left submit-button" onclick='myFun()'>Home</button>
<script>
myFun(){
$('form').attr('action','new path');
}
</script>
只是另一种变体:
<body>
<button name="redirect" onClick="redirect()">
<script type="text/javascript">
function redirect()
{
var url = "http://www.(url).com";
window.location(url);
}
</script>
用这个:
<button onclick="window.location='page_name.php';" value="click here" />
基本上你是使用javascript片段重定向和onclick事件的按钮触发它。