Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.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
jquery在单独的div中追加_Jquery_Append - Fatal编程技术网

jquery在单独的div中追加

jquery在单独的div中追加,jquery,append,Jquery,Append,我有一个画廊,标题应该是我的标题。 现在我想在画廊外的一个单独的分区中显示标题。 这就是我如何通过图像获得标题的方法。 但是如何将显示图像的标题附加到单独的div中呢 var appendCaptions = function(){ // cycle through each child slider.children.each(function(index){ // get the image title attribute

我有一个画廊,标题应该是我的标题。 现在我想在画廊外的一个单独的分区中显示标题。 这就是我如何通过图像获得标题的方法。 但是如何将显示图像的标题附加到单独的div中呢

var appendCaptions = function(){
        // cycle through each child
        slider.children.each(function(index){
            // get the image title attribute
            var title = $(this).find('img:first').attr('title');
            // append the caption
            if (title != undefined && ('' + title).length) {
                $(this).append(title);
            }
        });
    }


<ul class="bxslider">
              <li><img src="images/1.jpg" title="Happy trees" /></li>
              <li><img src="images/1.jpg" /></li>
              <li><img src="images/1.jpg" title="Happy tre333es" /></li>
              <li><img src="images/1.jpg" title="Happy treeffees" /></li>
            </ul>
<div class='title'></div>
var appendCaptions=function(){
//循环遍历每个孩子
slider.children.each(函数(索引){
//获取图像标题属性
var title=$(this.find('img:first').attr('title');
//附加标题
if(title!=未定义(“”+title).length){
$(本)。附加(标题);
}
});
}

我希望标题显示在div标题内;我使用的滑块是bxslider,您需要在每个迭代器中中断循环,因此请尝试:

var appendCaptions = function(){
        // cycle through each child
        slider.children.each(function(index){
            // get the image title attribute
            if( $(this).is(':visible')){
            var title = $(this).find('img:first').attr('title');
            // append the caption
            if (title != undefined && ('' + title).length) {
                $('#myDiv').append(title);
                return false;
            }
          }
       });
    }

这就是你要找的吗

$("#myTitleDiv").html(title);
这是非常棒的。

放置一些HTML

我想你是想:

  • 获取每个滑块图像的标题
  • 将标题附加到作为此图像容器的每个div
也许可以试试这样:

var appendCaptions = function(){
        // cycle through each child
        slider.children.each(function(index){
        // get the image title attribute
        var title = $(this).find('img:first').attr('title');
        // append the caption
        if (title != undefined && ('' + title).length) {
            $(this).parents("div.singleImgContainer").append(title);
        }
    });
}

这将找到类为singleImgContainer的div,并将标题放在其中。

您只需通过适当的选择器获取元素并附加到它:)例如$(“#myDiv”)。附加(标题);我试过了,但后来我得到了div中的所有标题,但我只想要显示图像的标题。你说的显示图像是什么意思?幻灯片中显示的图像,你的代码出现了什么问题?对我不起作用!它使滑块始终处于加载状态!请更准确地添加以下问题:)好的,似乎有些东西仍然不起作用!我得到了第一张图片的标题,但当我转到下一张图片时,标题没有改变!我正在使用bxslider!我修改了bxslider的jquery!不,我得到了div中的所有标题,而不是显示的图像中的一个,没有标题!我尝试了$(this.parents().find('.titles').append(title);但我又得到了所有的头衔!代码是可以的,但我的假设是错误的,但这是因为你的问题缺乏细节。