簡體   English   中英

在Javascript中激活鏈接

[英]Making links active in Javascript

我有一些Javascript的問題。 事實上,我只是那種腳本語言的新手,所以我需要一些幫助。問:如何激活此鏈接:

<a href="#box1">something</a>

此鏈接只是鏈接到位於index.html文件中的div,因此沒有頁面加載。 這是div

<div id="box1" class="box">
<h3><a name="box1">something</a></h3>
</div>

由於你剛剛開始,我建議你使用像jQuery這樣的庫。 所以,如果您的HTML是這樣的:

<div id="box1" class="box">
<h3><a name="box1">something</a></h3>
</div>
<div id="box2" class="box">
<h3><a name="box2">something</a></h3>
</div>
<div id="box3" class="box">
<h3><a name="box3">something</a></h3>
</div>

你有一個名為youarehere的CSS類:

.youarehere { color:white; background:green; }

使用jQuery,您可以編寫以下內容:

$(".box > a").click(function() {             // when clicking any of these links
    $(".box > a").removeClass("youarehere"); // remove highlight from all links
    $(this).addClass("youarehere");          // add highlight to clicked link
})

在簡單的JS中,實現這一點需要更多的努力。 幫自己一個忙,不要重新發明輪子 - 人們已經照顧好了這一點,所以用他們的勞動產品讓你的生活更輕松。

a:active表示當您單擊鏈接時,css屬性將應用於鏈接,而不是使用:active use

a.visited{color:red;}

要更改鼠標上的鏈接文本顏色,請使用以下css:

<style type="text/css">
        a:hover{color:Red;}
    </style>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM