我正在玩w3schools Tryit编辑器中的按钮,我试图弄清楚如何让我的浏览器重定向到一个URL,当我点击取消按钮。
以下是我尝试过的内容:
< form action =demo_form.aspmethod =get>名字:< input type =textname =fname>< br>姓氏:< input type =textname =lname>< br> <按钮类型=提交值=提交>提交< /按钮> <按钮类型=重置值=重置>重置< /按钮> < button type =cancelonclick =javascript:window.location ='http://stackoverflow';>取消< / button>< / form>
但它不起作用。任何想法?
解决方案取消不是有效的类型值属性,所以该按钮可能默认为 submit 并继续提交表单。您可能意指 type =button。
( javascript:应该被删除,虽然它没有任何伤害,但它是完全没有用的标签)
虽然没有类似按钮的功能,但最好使用:
< a href =stackoverflow>取消< / a>...可能带有一些CSS使它看起来像一个按钮。
I am playing with the Buttons in the w3schools Tryit editor, and I am trying to figure out how to make my browser redirect to an URL when I click on the "Cancel" button.
Here's what I have tried:
<form action="demo_form.asp" method="get"> First name: <input type="text" name="fname"><br> Last name: <input type="text" name="lname"><br> <button type="submit" value="Submit">Submit</button> <button type="reset" value="Reset">Reset</button> <button type="cancel" onclick="javascript:window.location='stackoverflow';">Cancel</button> </form>
But it doesn't work. Any ideas?
解决方案cancel is not a valid value for a type attribute, so the button is probably defaulting to submit and continuing to submit the form. You probably mean type="button".
(The javascript: should be removed though, while it doesn't do any harm, it is an entirely useless label)
You don't have any button-like functionality though, so would be better off with:
<a href="stackoverflow"> Cancel </a>… possibly with some CSS to make it look like a button.
更多推荐
如何创建一个重定向到URL的HTML取消按钮
发布评论