Usage of the target attribute of the html tag a

Usage of the target attribute of the html tag a
1: If you use the tag <a> to link to a page, I believe everyone knows the role of the target attribute. It refers to the form in which the linked page is displayed. Commonly used values ​​of target are: _blank (open the linked page in a new pop-up browser window) and _self (open the linked page in the original window). Of course, there are also _top and so on, but since they are not commonly used, I will not introduce them here.
For example: <a href="http://jb51.net" target="_blank">123WORDPRESS.COM </a> means to link to 123WORDPRESS.COM and open it in a new window
2: If you use the tag <a> to trigger an action (after the action is completed, you usually jump to a certain page). This action can be divided into two types here:
(1) Actions that do not submit a form (i.e., actions that do not operate on the form). Relevant scenarios in web development, such as deleting a single record, are not very complicated, and do not require many parameters, all of which are submitted in get mode. At this time, you can specify the display format of the page to be jumped to through the target attribute. The usage here is the same as described in 1.
for example
<a href="http://jb51.net/user/deleteAction.do?id=5" target="_self">Delete Xiao Ming</a> means that after the action is processed, a new page will be opened in this window.
(2) The action of submitting in the form of a form (i.e., the action of submitting the data in the form). Such applications are common in web development, such as user registration, information modification, etc. Of course, some people will say that the data in the form can be submitted directly using <input type="submit"> or <input type="button">. But in some cases, you may prefer to submit in the form of <a href="javascript:your js function name">. If you submit it in the form of a tag <a>, and you want to use the attribute target to control the page to jump to after processing, it will not work. At this time, the target attribute is no longer effective. Instead, you should set it in the target attribute of the form to achieve what you want!
for example:

Copy code
The code is as follows:

function check(){ //Verify that it is not empty
if(form1.username.value=""){
return;
}
form1.submit();
}
<form action="http://china.com/user/addAction.do" target="_blank" name="form1">
<input type="text" name="username" >
</form>
<a href="javascript:check();" target="_self">Submit</a>

Indicates that after the action is processed, a new page is opened in a new window. (Although the target attribute of the tag <a> is set here, it will not take effect; instead, the target attribute of the form will take effect).

<<:  A brief discussion on CSS blocking merging and other effects

>>:  Docker sets up port mapping, but cannot access the solution

Recommend

js to achieve interesting countdown effect

js interesting countdown case, for your reference...

How to distinguish MySQL's innodb_flush_log_at_trx_commit and sync_binlog

The two parameters innodb_flush_log_at_trx_commit...

HTML form tag tutorial (3): input tag

HTML form tag tutorial, this section mainly expla...

Talking about the practical application of html mailto (email)

As we all know, mailto is a very practical HTML ta...

WeChat applet example of using functions directly in {{ }}

Preface In WeChat applet development (native wxml...

Talk about the 8 user instincts behind user experience in design

Editor's note: This article is contributed by...

The background color or image inside the div container grows as it grows

Copy code The code is as follows: height:auto !im...

How to set up Spring Boot using Docker layered packaging

The Spring Boot project uses docker containers, j...

Let’s take a look at JavaScript precompilation (summary)

JS running trilogy js running code is divided int...

How to add Nginx to system services in CentOS7

Introduction After compiling, installing and solv...

Detailed installation and configuration of MySql on Mac

1. Download and install Download the community ed...