HTML 更改

悬停时的文字

发布于 2025-01-13 22:13:27 字数 181 浏览 1 评论 0原文

大家好,我正在制作一个作品集,因为我的互联网名称是 unofficialdxnny,所以当查看者将鼠标悬停在名称 unofficialdxnny 上时,我想在网站上进行此操作 < ;h1> 更改为不同的文本。其中文字是我的真实姓名。

这可能吗?

Hi so I am making a portfolio and since my internet name is unofficialdxnny I wanted to make it so on the website when the viewer hovers on the name unofficialdxnny the <h1> changes to a different text. where the text would be my real name.

Is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

べ繥欢鉨o。 2025-01-20 22:13:27
//your text element
let text = document.getElementById("text");
//checks for hover
text.addEventListener("mouseenter", function( event ) {
   //sets text
   text.innerHTML = "test2";

     setTimeout(function() {
    //sets text after some time
    text.innerHTML = "test1";
  }, 500);
}, false);
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>hover text</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
  </head>
  <body>
    <h1 id="text">test1</h1>
    <script src="script.js"></script>
  </body>
</html>

希望这有效

//your text element
let text = document.getElementById("text");
//checks for hover
text.addEventListener("mouseenter", function( event ) {
   //sets text
   text.innerHTML = "test2";

     setTimeout(function() {
    //sets text after some time
    text.innerHTML = "test1";
  }, 500);
}, false);
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>hover text</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
  </head>
  <body>
    <h1 id="text">test1</h1>
    <script src="script.js"></script>
  </body>
</html>

hope this works

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文