gpt4 book ai didi

javascript - 鼠标悬停时更改 DIV 内容

转载 作者:行者123 更新时间:2023-11-30 08:03:03 27 4
gpt4 key购买 nike

我有一个用于内容显示的现有脚本。目前,当您单击链接时它会起作用。是否可以修改它以在鼠标悬停而不是单击时工作。

这是我的 fiddle :

HTML:

<a href="#" id="1"><div class="block"></div></a>
<a href="#" id="2"><div class="block"></div></a>
<a href="#" id="3"><div class="block"></div></a>

<div class="content"></div>

JavaScript:

$( document ).ready(function() {
$('#1').click();
});

$('#1').click(function() {
$('.content').html('This is a text example 1');
});

$('#2').click(function() {
$('.content').html('This is a text example 2');
});

$('#3').click(function() {
$('.content').html('This is a text example 3');
});

最佳答案

只需将 click() 更改为 mouseover();

您也可以使用 mouseenter()。请参阅链接以获取更多说明 (link)。

DEMO

$( document ).ready(function() {
$('#1').mouseover();
});

$('#1').mouseover(function() {
$('.content').html('This is a text example 1');
});

$('#2').mouseover(function() {
$('.content').html('This is a text example 2');
});

$('#3').mouseover(function() {
$('.content').html('This is a text example 3');
});

关于javascript - 鼠标悬停时更改 DIV 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23408129/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com