Image 引导2模式动态加载映像

Image 引导2模式动态加载映像,image,twitter-bootstrap,load,modal-dialog,Image,Twitter Bootstrap,Load,Modal Dialog,我试图在bootstrap3模式上动态加载一个映像 当我第一次点击缩略图时,我得到了图像的源代码。 当我关闭模态并再次单击缩略图时,它工作正常 我的jQuery代码: jQuery('.featuredimglink').click( function(event) { event.preventDefault(); jQuery('.modal-body').empty(); var title = jQuery(this).attr("title"); jQ

我试图在bootstrap3模式上动态加载一个映像

当我第一次点击缩略图时,我得到了图像的源代码。 当我关闭模态并再次单击缩略图时,它工作正常

我的jQuery代码:

jQuery('.featuredimglink').click( function(event) {
    event.preventDefault();
    jQuery('.modal-body').empty();
    var title = jQuery(this).attr("title");
    jQuery('h3.modal-title').html(title);
    var img = (jQuery(this).find('img').attr('src')).replace('-150x150', '');
    jQuery('.modal-body').html('<img src="'+ img +'" alt="'+ title +'" />');
    jQuery('#myModal').modal({show:true});
});
引发一个错误:

未捕获的TypeError:对象[Object Object]没有方法“modal”


已解决

只是在单击函数之前初始化模态。这是我的最终代码:

  var mymodal = jQuery('#myModal').modal({
    show: false
  });

  jQuery('.featuredimglink').on('click', function(event) {
        event.preventDefault();
        jQuery('.modal-body').empty();
    var title = jQuery(this).attr("title");
    jQuery('h3.modal-title').html(title);
    var img = (jQuery(this).find('img').attr('src')).replace('-150x150', '');
    jQuery('.modal-body').html('<img src="'+ img +'" alt="'+ title +'" />');
    mymodal.modal('show');
   });
var mymodal=jQuery('#mymodal').modal({
节目:假
});
jQuery('.featuredimglink')。在('click',函数(事件){
event.preventDefault();
jQuery('.modal body').empty();
var title=jQuery(this).attr(“title”);
jQuery('h3.modal title').html(title);
var img=(jQuery(this).find('img').attr('src')).replace('-150x150','');
jQuery('.modal body').html('');
mymodal.modal('show');
});

如果在模式对话框中使用引导,则需要引用引导css和引导js文件

<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>


很抱歉,这是bootstrap 2,包括jQuery和bootstrap、js和css文件。
  var mymodal = jQuery('#myModal').modal({
    show: false
  });

  jQuery('.featuredimglink').on('click', function(event) {
        event.preventDefault();
        jQuery('.modal-body').empty();
    var title = jQuery(this).attr("title");
    jQuery('h3.modal-title').html(title);
    var img = (jQuery(this).find('img').attr('src')).replace('-150x150', '');
    jQuery('.modal-body').html('<img src="'+ img +'" alt="'+ title +'" />');
    mymodal.modal('show');
   });
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
jQuery('#myModal').modal({show:true});
jQuery('#myModal').modal('show');