如何创建一个重定向到URL的HTML取消按钮

编程入门 行业动态 更新时间:2024-10-05 03:22:20
本文介绍了如何创建一个重定向到URL的HTML取消按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在玩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取消按钮

本文发布于:2023-11-02 06:33:28,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:创建一个   重定向   按钮   URL   HTML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!