单击后更改按钮链接 [英] Change button link after click
问题描述
我在具有onsubmit='return false'
的<form>
内有一个<button>
元素,因此,如果我尝试在<a>
标记内链接按钮,则不会调用该按钮.现在,如果您单击该按钮,它将执行动画,并且由于onsubmit
返回false,因此不会重新加载页面,但是我希望使用同一按钮打开https://google.com
,即单击一次后,我已经尝试过使用JQuery将属性method=GET action=google.com
添加到表单中
一旦单击按钮,但它会在第一次单击时打开google,而不是在第二次单击时打开.有什么想法吗?
I have a <button>
element inside a <form>
that has onsubmit='return false'
so if I try to link the button inside an <a>
tag it won't be called. Right now if you click that button it will execute an animation, and since onsubmit
returns false the page isn't reloaded, but I want that same button to open https://google.com
i.e. after it has been clicked once, I've tried adding the attributes method=GET action=google.com
to the form using JQuery
once the button is clicked but it opens google on the first click, not in the second one. Any ideas?
<form class="box" id="box" onsubmit="return false">
<button class="sign-button">Submit</button>
</form>
推荐答案
这必须使用JavaScript来完成.在下面的示例中,我使用了 jQuery 使其更简单.
This will have to be done in JavaScript. In the example below I've used jQuery to make it simpler.
var checkedAlready = false;
$('.box button.sign-button').click(function () {
if (!checkedAlready) {
// Do animation...
checkedAlready = true;
} else {
location.href = "http://google.com";
}
});
这篇关于单击后更改按钮链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!