簡體   English   中英

用 jquery 制作兩個錨標簽

[英]making two anchor tags with jquery

當鼠標進入#intro並隱藏介紹以及鼠標離開原始介紹顯示時,我希望添加兩個錨鏈接。

$("#intro").on("mouseenter", function() {
  var link = $("<a>");
  var link2 = $("<a>");

  link.attr("href", "en.html");
  link2.attr("href", "fr.html");

  link.text("Welcome!");
  link2.text("Bienvenue!");

  $("#intro").addClass("link link2");
  $("#intro").html(link && link2);
});

$("#intro").on("mouseleave", function() {
  show(slow, this)
});

jQuery:

 $(document).ready(function(){ $("#intro").mouseover(function() { $(this).addClass("link link2"); $("#intro a").show(); $("#intro h1").hide(); }); $("#intro").mouseout(function() { $(this).removeClass("link link2"); $("#intro a").hide(); $("#intro h1").show(); }); });
 #intro { width: 200px; height: 200px; background-color: red; margin: 20px auto; } #intro a{ display:none; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id="intro"> <h1>Intro</h1> <a href='en.html'>Welcome.</a> <a href='fr.html'>Bienvenue!</a> </div>

CSS:

 #intro { width: 200px; height: 200px; background-color: red; margin: 20px auto; display: flex; justify-content: center; align-items: center; } #intro a, #intro:hover h1{ display:none; } #intro:hover a{ display: block; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id="intro"> <h1>Intro</h1> <a href='en.html'>Welcome.</a> <a href='fr.html'>Bienvenue!</a> </div>

暫無
暫無

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

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