How to add "confirm" to hyperlinks in Web pages

Source: Internet
Author: User

Recently in the database, you need to give a "delete" link to increase the confirmation of the popup box, found on the Internet two methods:

1, first look at one of the most troublesome

<HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><title>Untitled Document</title><Script>functioncon () {varCFM=Confirm ("are you sure ?"); if(CFM) {window.location.href="http://www.baidu.com"; }}</Script></Head><Body><ahref= "Javascript:con ()">Baidu Link</a></Body></HTML>

The principle of this method is to judge confirm true or false, if true, then I will put http://www.baidu.com, to the HREF, if False, then the HREF is a null value.

2, the simplest way to use the onclick attribute in the <a></a> tag

<href= "http://www.baidu.com"  onClick= "return confirm (' Confirm? ')" > Baidu link </a>

The OnClick property in this method is similar to the onsubmit in the <form> form, and returns true to jump, return false you just stay where you are.

But if the application in the link database, both methods are not very useful, because the code involved in too many quotes, a variety of single and double quotation marks coexist, so here I summed up another way, with a function to add a confirmation link, relative to the database is more practical method , write confirm into a function

<HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><title>Untitled Document</title><Script>functioncon () {varCFM=Confirm ("are you sure ?"); if(CFM) {return true; }    Else {        return false; }}</Script></Head><Body><aonclick= "return con ()"href= "Http://www.baidu.com">Baidu Link</a></Body></HTML>

The knowledge used in this place is not many, but in general the knowledge of data type is used, and the five big data types must be understood deeply

<Script>functionTo () {vara= 5; varb= "Nihao"; varC= function(){}; varD= NULL; vare= true; Alert (typeofa); //data type is numberAlert (typeofb); //data type is stringAlert (typeofc); //data type is functionAlert (typeofd); //data type is ObjectAlert (typeofe); //data type is Boolean}to ();</Script>

In fact, the data type is far more than the five kinds, the following figure can be broadly summarized

How to add "confirm" to hyperlinks in Web pages

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.