jQuery追加缩略图返回" undefined"

时间:2014-04-05 14:49:22

标签: jquery

我需要第二眼看这个是代码:

$(function() {
    thumbnails = ['images/image1.png', 'images/image2.png', 'images/image3.png', 'images/image4.png', 'images/image5.png', 'images/image6.png', 'images/image7.png', 'images/image8.png']
    $('#images img').click(function(e) {
        e.preventDefault();
        var newImage = $('<img src="' + thumbnails.filename + '"/>');
        var dragdiv = $('<div class="draggable">' + newImage.value + '</div>');
        $('#imageBox').append(dragdiv);
        $('.draggable').draggable({
        scroll: false,
        containment: '#imageBox'
        });
        $('.draggable img').resizable({
        handles: "all"
    });
});

});

1 个答案:

答案 0 :(得分:0)

使用

var newImage = '<img src="' + thumbnails.filename + '"/>';
var dragdiv  = '<div class="draggable">' + newImage.value + '</div>';

而不是

var newImage = $('<img src="' + thumbnails.filename + '"/>');
var dragdiv  = $('<div class="draggable">' + newImage.value + '</div>');

NEW EDIT :我希望这就是你要找的东西

$(function()
{
$('#images img').click(function(e) {
e.preventDefault();

 var newImage = '<img src="' + $(this).attr('src') + '"/>';
 var dragdiv  = '<div class="draggable">' + newImage + '</div>';

    $('#imageBox').append(dragdiv);
    $('.draggable').draggable
        ({
            scroll: false,
            containment: '#imageBox'
    });

    $('.draggable img').resizable({
            handles: "all"
    });
}); 
});