I used to write the href and onclick of very casually. Later, several problems occurred, and then I started to pay attention to this issue:
##First excerpt A document:
In Javascript, void is an operator, which specifies that an expression is to be evaluated but does not return a value.
void operator usage format is as follows:
1. javascript:void (expression) 2. javascript:void expression
expression is a Javascript standard expression to be evaluated. The parentheses outside the expression are optional, but are a good practice to write. (Implementation version Navigator 3.0)
You can use the void operator to specify a hyperlink. The expression will be evaluated but nothing will be loaded into the current document.
The following code creates a hyperlink that will cause nothing to happen to the user later. When the user links, void(0) evaluates to 0, but has no effect on the Javascript.
<A HREF="javascript:void(0)">单此处什么也不会发生</A>
The following code creates a hyperlink that will submit the form when the user clicks.
<A HREF="javascript:void(document.form.submit())">
Submit form here
The following code executes the subgo() function,
<a href="javascript:void(0)" onclick="subgo()">点我</a>
Here, javascript:void(0) has no actual function. It is just a dead link, and the executed function is subgo().
点我与<a href="javascript:void(0)" onclick="subgo()">点我</a>区别。
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();", document It is recommended to write like this: xx, but this method sometimes causes strange problems in complex environments, so try not to Using javascript: protocol as the href attribute of A will not only cause the window.onbeforeunload event to be triggered unnecessarily, but will also cause the gif animated image to stop playing 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 Action execution, onclick needs to return false, generally write onclick="xxx();return false;".
JS source code of TabPane, because 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.
TabPane.prototype.appendTitle = function(tabpage){ var td = $create("td"); var strHTML = "<table class="" + TAB_STYLE_TABLE + "" border="0" cellspacing="0" cellpadding="0"><tr>"; strHTML +="<td><p class=""+TAB_STYLE_LEFT+""></p></td>"; strHTML +="<td nowarp class=""+TAB_STYLE_MID+"">"; strHTML +="<p style="white-space:nowrap;page-break-before: always;page-break-after: always;">"; strHTML += tabpage.getTitle(); strHTML +="</p></td>"; if(tabpage.showCloseButton){ strHTML +="<td nowarp class=""+TAB_STYLE_MID+"">"; strHTML +="<a class="close" href="#" onclick="$o(\"" + this.id + "\").getTab(\"" + tabpage.id + "\").close(); return false; ">"; if(isIE){ strHTML +="<p></p></a>"; }else{ strHTML +="<p class="close"></p></a>"; } strHTML +="</td>"; } if(tabpage.allowReload){ strHTML +="<td nowarp class=""+TAB_STYLE_MID+"">"; strHTML +="<a class="reload" href="#" onclick="$o(\"" + this.id + "\").getTab(\"" + tabpage.id + "\").reload(); return false; ">"; if(isIE){ strHTML +="<p></p></a>"; }else{ strHTML +="<p class="reload"></p></a>"; } strHTML +="</td>"; } strHTML +="<td><p class=""+TAB_STYLE_RIGHT+""></p></p>"; strHTML +="</td></tr></table>"; td.className = TAB_STYLE_NOMAL + this.styleSuffix; td.innerHTML = strHTML; tabpage.__titleTD = td; tabpage.setTitleTD(); tabpage.initStatus(); this.__titleTR.insertBefore(td,this._titleTD); tabpage.titleWidth = td.offsetWidth; }
The above is the detailed content of Detailed introduction to href and onclick of a tag in html. For more information, please follow other related articles on the PHP Chinese website!

The usage methods of HTML tags and attributes include: 1. Basic usage: Use tags such as and, and add necessary information through attributes such as src and href. 2. Advanced usage: Use data-* custom attributes to achieve complex interactions. 3. Avoid common mistakes: Make sure the property values are surrounded by quotes. 4. Performance optimization: Keep it simple, use standard attributes and CSS class names to ensure that the image has alt attributes. Mastering these will improve web development skills.

HTMLtagsdefinethestructureofawebpage,whileattributesaddfunctionalityanddetails.1)Tagslike,,andoutlinethecontent'splacement.2)Attributessuchassrc,class,andstyleenhancetagsbyspecifyingimagesources,styling,andmore,improvingfunctionalityandappearance.

The future of HTML will develop in a more semantic, functional and modular direction. 1) Semanticization will make the tag describe the content more clearly, improving SEO and barrier-free access. 2) Functionalization will introduce new elements and attributes to meet user needs. 3) Modularity will support component development and improve code reusability.

HTMLattributesarecrucialinwebdevelopmentforcontrollingbehavior,appearance,andfunctionality.Theyenhanceinteractivity,accessibility,andSEO.Forexample,thesrcattributeintagsimpactsSEO,whileonclickintagsaddsinteractivity.Touseattributeseffectively:1)Usese

The alt attribute is an important part of the tag in HTML and is used to provide alternative text for images. 1. When the image cannot be loaded, the text in the alt attribute will be displayed to improve the user experience. 2. Screen readers use the alt attribute to help visually impaired users understand the content of the picture. 3. Search engines index text in the alt attribute to improve the SEO ranking of web pages.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML is used to build web page structure; 2. CSS is used to beautify the appearance of web pages; 3. JavaScript is used to achieve dynamic interaction. Through tags, styles and scripts, these three together build the core functions of modern web pages.

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform


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

Dreamweaver CS6
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
