javascript - 为什么此图像 slider 在模式中不起作用?

标签 javascript php jquery twitter-bootstrap

当模式打开时,我显示图像 slider /轮播。但是,当我单击图像时, slider 不会显示。该代码使用 javascript 生成,然后由 php 页面呈现。

我正在从服务器端发送一个 JSON 对象。我得到它没有任何错误。 在该 JSON 对象中,我得到了 3 张图像,我想将它们显示在 slider 中。任何图像都可能是空白的。 这是我所做的:

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');
    });

最佳答案

我相信您在显示这样的模式后需要调用 $('.carousel').carousel()

$('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()
});

关于javascript - 为什么此图像 slider 在模式中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35651871/

相关文章:

javascript - nodejs 中的 mysql 函数第一次工作

php - MySQL简单论坛

PHP shell_exec ssh连接

Jquery 动画属性?

javascript - 如果复选框被选中,则功能是否被选中,如果未被选中,则功能不同?

javascript - 没有旋转的转换属性的 CSS 转换

javascript - 如何克隆函数

javascript - 在 javascript 中附加事件监听器时的对象范围

php - 显示从组合框中选择的搜索选项的所有结果

javascript - 在javascript中将两个数组组合成一个对象