


The difference and priority between href and onclick usage in Html's a tag
This article mainly shares an article about the usage, difference, and priority of href and onclick in the Html A tag. It has a good reference value. Friends who need to know more can take a look.
If you do not set the href attribute in IE6 will not respond to hover. After double-clicking, the parent container of the label will be selected instead of the a label (this problem exists under IE).
The code is as follows
1 |
|
Suppose we have a fn method that needs to get this element. The this passed in by the first method is a null value.
So, the more recommended way to write is
The code is as follows
1 |
|
The following code executes the subgo() function,
The code is as follows
1 |
|
Here, javascript:void(0) has no actual function. It is just a dead link, and the executed function is subgo().
The code is as follows
1 |
|
In fact, # contains a location information. The default anchor is #top, which is the top of the web page, and javascript:void(0) only represents a dead link without any information. Therefore, it is best to use void(0) when calling a script
href generally points to a URL address, you can also call javascript, such as href="javascript:xxx();", the document recommends writing like this:
The code is as follows
1 |
|
However, this method sometimes causes strange problems in complex environments. Try not to use javascript: protocol as the href attribute of A. This will not only cause unnecessary triggering of the window The .onbeforeunload event will stop the playback of animated gif images in IE.
We know that the onclick event of the link is executed first, followed by the action under the href attribute (page jump, or javascript pseudo link). If you do not want to execute the action under the href attribute, onclick needs to return false. Generally, onclick="xxx();return false;".
JS source code of TabPane is written like this. Since onclick does not return FALSE, when TABPANE is closed in IFRMAE, it will cause href execution and page display problems. The solution is to copy the following code into the JSP using TAB.
The problem of using href and onclick at the same time in Html A tag Priority level
1 Order
ie 6: href triggers onclick first and then triggers
Other browsers trigger onlick first and then triggers href
2 href="javascript: xxx()"
This cannot be passed in as a parameter
onclick can
The code is as follows
1 |
|
3 If the method that is triggered first returns false, the latter event will not be triggered.
For example
The code is as follows
1 |
|
4
will cause The page is positioned at the bookmark position,
1) When there is no need to pass this as a method parameter, it is recommended to
2) If you need to use this parameter, it is recommended that
<a href="javascript:void(0);" onclick="doSomthing( this)" >
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
The difference between using javascript in the href and onclick of a tag
will be different when holding down the Shift key.
The problem I encountered today is that I cannot access parentNode in the form of href in IE6.0.
That’s all, I spent a lot of time on this.
1 2 |
|
It is finally implemented using parentNode.
The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
Explanation on the usage of HTML's a tag href attribute to specify relative paths and absolute paths
The above is the detailed content of The difference and priority between href and onclick usage in Html's a tag. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











index.html represents the home page file of the web page and is the default page of the website. When a user visits a website, the index.html page is usually loaded first. HTML (HypertextMarkupLanguage) is a markup language used to create web pages, and index.html is also an HTML file. It contains the structure and content of a web page, as well as tags and elements used for formatting and layout. Here is an example index.html code: <

src and href are respectively, 1. src is the abbreviation of source, which is used to specify the path of external resources. It is usually used to embed external files, such as pictures, audios, videos, etc. The src attribute is generally used on img, script, iframe and other tags. ; 2. href is the abbreviation of hypertext reference, which is used to specify the path of the target resource of the hyperlink. It is usually used to link to external documents or other pages. The href attribute is generally used on tags such as a and link.

To remove the inherent color of the a tag, you can use the following method: Use the CSS color property to specify the text color. Use the CSS link-color property to specify link color. Use the CSS text-decoration property to remove underline and default text color. Use the CSS hover color property to change the text color on mouseover. Use the CSS visited color property to change the text color of visited a tags.

a tag to create a hyperlink, and then through the a tag, you can link one page to another page. Detailed introduction: To achieve page jump, you need to fill in the URL of the target page into the href attribute. The URL can be a relative path or an absolute path. The relative path is the path relative to the current page, and the absolute path is the complete URL. address.

When writing a website or application, you often encounter the need to jump to a specific page. In PHP, we can achieve page jump through several methods. Below I will demonstrate three common jump methods for you, including using the header() function, using JavaScript code, and using meta tags. Using the header() function The header() function is a function used in PHP to send original HTTP header information. This function can be used in combination when implementing page jumps. Below is a

The a tag attributes are: 1. href; 2. target; 3. rel; 4. download; 5. hreflang; 6. type. Detailed introduction: 1. href, which defines the target URL of the link. This is the most commonly used attribute of the "<a>" tag. It can link to any part of the web page, such as the top of the page, a specific paragraph, etc.; 2. target, which defines the link in Where to open; 3. rel, defines the relationship of the link. This attribute allows specifying the relationship between the current document and the linked document, etc.

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: <

Title: Implementation method of page jump in 3 seconds: PHP Programming Guide In web development, page jump is a common operation. Generally, we use meta tags in HTML or JavaScript methods to jump to pages. However, in some specific cases, we need to perform page jumps on the server side. This article will introduce how to use PHP programming to implement a function that automatically jumps to a specified page within 3 seconds, and will also give specific code examples. The basic principle of page jump using PHP. PHP is a kind of
