gpt4 book ai didi

javascript - Jquery onclick 缩略图功能。

转载 作者:行者123 更新时间:2023-12-03 12:13:33 24 4
gpt4 key购买 nike

我的 friend 给了我一个使用 Jquery 的 javascript,我不太明白它是如何工作的,尤其是“.thumbnails > div”。以及为什么在同一行中调用相同的函数。谁能用英语解释一下下面的内容?

$(function(){
$(document).on('click', '.thumbnails > div', function(){
var img = $(this).find('img').attr('src');
$('.bigImage').attr('src', img);
});
});

最佳答案

我会尝试为您添加一些注释:

// when the DOM is ready
$(function(){
// find an element that has a class "thumbnails" - then find all
// divs that are directly underneath it
// and attach a click event handler
$(document).on('click', '.thumbnails > div', function(){
// when you click -> find an img element under the div that was
// clicked on and get its source attribute
var img = $(this).find('img').attr('src');

// find an element with a class "bigImage" and change its source
// attribute to the one selected before
$('.bigImage').attr('src', img);
});
});

关于javascript - Jquery onclick 缩略图功能。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24837222/

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