How to create a HTML Cancel button that redirects to a URL

前端 未结 11 1149
Happy的楠姐
Happy的楠姐 2020-12-13 13:00

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.

11条回答
  •  轮回少年
    2020-12-13 13:46

    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:

     Cancel 
    

    … possibly with some CSS to make it look like a button.

提交回复
热议问题