Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.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
Javascript jquery将每个位置重置为默认位置的最佳方法是什么?_Javascript_Jquery - Fatal编程技术网

Javascript jquery将每个位置重置为默认位置的最佳方法是什么?

Javascript jquery将每个位置重置为默认位置的最佳方法是什么?,javascript,jquery,Javascript,Jquery,我有一些缩略图点击后,它会显示用户的所有作品,例如用户1有1个作品,用户2有6个作品。当然,我会根据用户的作品数量来显示div。如果我点击用户1,它显示1个工作,我退出并点击用户2,而不是6个工作,它只显示1,因为该函数采用了在用户1上设置的功能,因为我没有重置。。因此,我想知道是否有最佳实践可以在退出时将show/hide div重置为默认值,我现在知道的唯一解决方案是在每次函数激活时调用.show,但这似乎不是一个好方法。请告知 范例 $(function() { $(".img_t

我有一些缩略图点击后,它会显示用户的所有作品,例如用户1有1个作品,用户2有6个作品。当然,我会根据用户的作品数量来显示div。如果我点击用户1,它显示1个工作,我退出并点击用户2,而不是6个工作,它只显示1,因为该函数采用了在用户1上设置的功能,因为我没有重置。。因此,我想知道是否有最佳实践可以在退出时将show/hide div重置为默认值,我现在知道的唯一解决方案是在每次函数激活时调用.show,但这似乎不是一个好方法。请告知

范例

$(function() {
    $(".img_thumb_holder").on('click', function() { 
        var index = $(this).index(); // get current index of clicked thumbnail, so i can call out the related name from captionArray via same index

        // what i did to solve the reseting, forcing it to show out each time the function runs
        $(".portfolio_thumbImg_holder").show();

        $.ajax({
            type: "POST",
            dataType: "json",
            data: ({id: idArray[index]}), // pass the name of clicked holder into php to query
            url: "CMS/PHP/retrieveAuthorWorks.php",
            success: function(data) {   
                console.log("Array consist of " + data)
                $('.portfolio_thumbImg_holder img').removeAttr("src");
                linksArray=[];  
                titleArray=[];  
                descArray=[];   
                $(".full_image_desc .title").html(data[0].title);
                $(".full_image_desc .info").html(data[0].desc);
                $('.portfolio_thumbImg_holder img').each(function(index, element) {                                                     
                      if (data[index]) {
                          linksArray.push("http://localhost/testdatabase/cms/" + data[index].links);
                          $(element).attr("src", linksArray[index]);
                          titleArray.push(data[index].title);
                          $(element).attr("title", titleArray[index]);
                          descArray.push(data[index].desc);
                          $(element).attr("desc", descArray[index]);
                        }
                }); 
                // check how many divs without the image data, and hide it
                $(".portfolio_thumbImg_holder img:not([src])").parent().hide();
            }
        });
    });
});

请将代码作为您所说内容的示例about@doniyor完成更新