Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有人能向noob解释一下jquery如何创建图像库吗?_Jquery - Fatal编程技术网

有人能向noob解释一下jquery如何创建图像库吗?

有人能向noob解释一下jquery如何创建图像库吗?,jquery,Jquery,我不明白这里发生了什么。如果有人能解释一下,我将不胜感激。我需要创建一个照片库,有人建议我看看这段代码,但我不明白它是如何工作的 $(document).ready(function(){ imageSwapper(".thumbnails a"); }); function imageSwapper(link) { $(link).click(function(){ $('#largeimage').attr('src', this.href); return fal

我不明白这里发生了什么。如果有人能解释一下,我将不胜感激。我需要创建一个照片库,有人建议我看看这段代码,但我不明白它是如何工作的

$(document).ready(function(){
  imageSwapper(".thumbnails a");
});

function imageSwapper(link) {
  $(link).click(function(){
    $('#largeimage').attr('src', this.href);
    return false;
  });
};
像这样:

// When the document is ready
$(document).ready(function(){
    // Call this function with this string (a CSS selector)
    imageSwapper(".thumbnails a");
});

function imageSwapper(link) {
    // With all the elements matching link (all the <a>'s under <tag class="thumbnails">)
    // Set their onClick to be this anonymous function
    $(link).click(function(){
        // Get the element with id="largeimage"
        // and set it's src attribute to the href of the link we clicked on
        $('#largeimage').attr('src', this.href);
        // Cancel the default action (don't go to the href of the link we clicked on
        return false;
    });
};
//文档准备就绪时
$(文档).ready(函数(){
//使用此字符串调用此函数(CSS选择器)
图像交换器(“缩略图a”);
});
功能图像交换器(链接){
//与所有元素匹配的链接(下的所有)
//将其onClick设置为此匿名函数
$(链接)。单击(函数(){
//获取id=“largeimage”的元素
//并将其src属性设置为我们单击的链接的href
$('#largeimage').attr('src',this.href);
//取消默认操作(不要转到我们单击的链接的href)
返回false;
});
};

文档准备事件行上有一个带有类缩略图的容器:

 imageSwapper(".thumbnails a");
将所述容器中的锚点(a)元素传递给函数immageSwapper

在功能上

 $(link).click(function()
将传递的锚元素的单击事件与函数绑定:

function(){
  $('#largeimage').attr('src', this.href);
  return false;
}

设置图像的src属性,该属性(*假定为*)将大图像显示为单击的锚元素的href属性值。

此代码将单击事件绑定到具有类缩略图的元素的子元素的所有链接。单击其中一个链接时,它将设置id=largeimage的元素的src属性

html可能如下所示:

<div class="thumbnails">
 <a href="image1.jpg"><img src="thumb1.jpg"/></a>
 <a href="image2.jpg"><img src="thumb2.jpg"/></a>
 <a href="image3.jpg"><img src="thumb3.jpg"/></a>
</div>
<img id="largeimage"/>