dsjuimtq920056 2016-02-26 12:33
浏览 40
已采纳

为什么此图像滑块在模态中不起作用?

I am showing an image slider/ carousel when the modal opens. However, the slider doesnt showup when I click the image. The code is generated using javascript and then rendered by the php page.

I am sending a JSON object from my server-side. I am getting it without any error. In that JSON object, I am getting 3 images which I want to display in a slider. Any image maybe blank. Here is what I have done:

displayData += '<div class="well well-sm" id="'+gotData.profile_id+'" style="width:180px;height:150px;background:#ccccff;display:block;float:left; border:1px solid black;padding: 5px;margin: 5px 5px 5px 5px;"';
displayData += '<p><b>'+gotData.first_name+'</b></p>';

if(gotData.img == "" && gotData.img2 == "" && gotData.img3 == ""){
displayData += '<p class="ethumbnail"> <img class="img-responsive" alt="Some image" src="images/no-image-found.png"  width="100" height="100" border=""/></p>';

displayData += '<p class="hidden"> <img class="img-responsive" alt="Some image" src="images/no-image-found.png"  width="200" height="200" border=""/></p>';
} else{

displayData += '<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">';
                                displayData += '<div class="carousel-inner">';

                                if(gotData.img != "" || gotData.img != undefined){
                                    displayData += '<p class="ethumbnail"> <img class="img-responsive" alt="Some image" src="data:image/jpeg;base64,'+gotData.img+'"  width="100" height="100" border=""/></p>';

    displayData += '<div class="item active">';
    displayData += '<p class="hidden"> <img class="img-responsive" alt="Some image" src="data:image/jpeg;base64,'+gotData.img+'"  width="100" height="100" border=""/></p>';
    displayData += '</div>';
    } else {} 

    if(gotData.img2 != "" || gotData.img2 != undefined){
        displayData += '<div class="item">';
        displayData += '<p class="hidden"> <img class="img-responsive" alt="Some image" src="data:image/jpeg;base64,'+gotData.img2+'"  width="100" height="100" border=""/></p>';
        displayData += '</div>';
    } else {}

    if(gotData.img3 != "" || gotData.img3 != undefined){
        displayData += '<div class="item">';
        displayData += '<p class="hidden"> <img class="img-responsive" alt="Some image" src="data:image/jpeg;base64,'+gotData.img3+'"  width="100" height="100" border=""/></p>';
        displayData += '</div>';                                    
    } else {}

    displayData += '</div>';
    displayData += '<a class="left carousel-control hidden" href="#carousel-example-generic" role="button" data-slide="prev">';
    displayData += '<span class="glyphicon glyphicon-chevron-left"></span>';
    displayData += '</a>';
    displayData += '<a class="right carousel-control hidden" href="#carousel-example-generic" role="button" data-slide="next">';
    displayData += '<span class="glyphicon glyphicon-chevron-right"></span>';
    displayData += '</a>';
    displayData += '</div>';
}

$('#content').html(displayData);//replacing img with data




$('body').on('click','div.well.well-sm',function(){
        var list = $(this);
        $('#myModal .modal-title').html('Profile Information');
        $('#myModal .modal-body').html(list.html());
        $('#myModal .modal-body p').removeClass('hidden');
        $('#myModal .modal-body p.ethumbnail').remove();
        $('#myModal').modal('show');
    });
  • 写回答

1条回答 默认 最新

  • dongxi1943 2016-02-26 12:36
    关注

    I believe you need to call $('.carousel').carousel() after you display the modal like this

    $('body').on('click','div.well.well-sm',function(){
        var list = $(this);
        $('#myModal .modal-title').html('Profile Information');
        $('#myModal .modal-body').html(list.html());
        $('#myModal .modal-body p').removeClass('hidden');
        $('#myModal .modal-body p.ethumbnail').remove();
        $('#myModal').modal('show');
        $('.carousel').carousel()
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀