<a href="#" onclick="myJsFunc();">Link</a>
<a href="javascript:void(0)" onclick="myJsFunc();">Link</a>
<a onclick="myJsFunc();">Link</a>
href帶值這可能是一種不好的做法。
原因如下:
時我們會遇到這種需要在a標簽上添加click事件,并且跳轉前處理一些事務,因此需要做一些處理,看很多人會這樣寫
<a href="#">link</a>,
但是發現點擊后頁面返回了頂部,所以又出現了這樣的寫法等
<a href="###">link</a>
但這樣并不兼容所有瀏覽器,有些瀏覽器就會出現很怪異的形為。 因此,這個問題還需要其它方法來解決。
<a href="javascript:void(0)">百度</a>
void是一個操作符,void(0)返回undefined,地址不發生跳轉
<a href="javascript:;">百度</a>
和以上相同,返回undefined
<a onclick="show()">百度</a> <script>
function show(){
alert("我沒跳轉");
return false;
}
擊藍字 關注我們
分享興趣,傳播快樂,增長見聞,留下美好!親愛的您,這里是Learning yard新學苑。今天小編為大家帶來《a標簽的使用方法》。
Share interest, spread happiness, increase knowledge, and leave behind beauty! Dear you, this is Learning yard New Academy. Today, Xiaobian brings you "How to Use A Label".
前端網頁的打開方式:
一般用標簽a來引用例如<a href=”#”></a>填寫#的地方就是你需要跳轉的網站例如:
How to open the front page:
Generally, web pages are quoted by the label A, for example < a href = "#" > </a > The place where # is filled in is the website you need to jump to, for example:
標簽中間寫字,就可以得到以下效果:
里頭的字默認就是藍色,有下劃線。當然字體也可以調整可以通過css里的text-decoration:none,來取消下劃線,通過color來調整字體顏色。代碼效果如下
The words in it are blue by default and underlined. Of course, the font can also be adjusted. You can cancel the underline by text-decoration: none in css, and adjust the font color by color. The code effect is as follows
咱們再回到網站最重要的一點就是打開方式,用target來引用,樣式為<a href=”#” target=””></a>,其中有blank,在新的一個頁面打開,self,在本頁面打開(默認為)parent(在a里面打開,以后知識齊全再講)以及top 和framename最常用的就是前兩個。
Let's go back to the website's most important point, which is how to open it. Use target to quote it, and the style is < a href = "#" target = "> </a >, among which blank, open on a new page, self, open on this page (default is) parent (open in A, we'll talk about it later), top and framename, and the most commonly used ones are the first two.
總結如下:
Summarize as follows:
今天的分享就到這里了。如果您對今天的文章有什么獨特的想法,歡迎評論留言,讓我們相約明天,祝您今天過得開心快樂!
That's it for today's sharing. If you have any unique ideas for today's article, please leave a comment, let us meet tomorrow, I wish you a happy day!
LearningYard學苑
分享興趣,傳播快樂,增長見聞,留下美好!少年易老學難成,一寸光陰不可輕
本文由learningyard新學苑原創,如有侵權,請聯系刪除。
翻譯來源:谷歌翻譯
排版:李仕陽
文本:李仕陽
審核:閆慶紅
*請認真填寫需求信息,我們會在24小時內與您取得聯系。