我看了一些其他帖子,我无法做出正面或反面。当页面加载时,jquery工作正常,当从ajax脚本加载相同的元素时,jquest不起作用。我知道我需要做一个回复但有些人可以告诉我这是怎么写的吗?
HTML:
<div id="item-list2">
<div class="content drag-desired">
<div class="product"><img src="img/products/iPod.png" alt="iPod" width="128" height="128" class="pngfix" />iPod</div>
<div class="product"><img src="img/products/iMac.png" alt="iMac" width="128" height="128" class="pngfix" />iMac</div>
</div>
</div>
jquery的:
$(document).ready(function(){
$(".product img").draggable({
containment: 'document',
opacity: 0.6,
revert: 'invalid',
helper: 'clone',
zIndex: 100
});
$("div.content.drop-here").droppable({
drop:
function(e, ui)
{
var param = $(ui.draggable).attr('src');
if($.browser.msie && $.browser.version=='6.0')
{
param = $(ui.draggable).attr('style').match(/src=\"([^\"]+)\"/);
param = param[1];
}
viewlist(param);
addlist(param);
}
});
});
Ajax脚本:
function viewlist(param)
{
$.ajax({
type: "POST",
url: "ajax/items.php",
data: 'img='+encodeURIComponent(param),
dataType: 'json',
beforeSend: function(x){$('#ajax-loader').css('visibility','visible');},
success: function(msg2){
$('#item-list2').append(msg2.txt);
}
});
}
答案 0 :(得分:2)
如果您将所有可拖动/可放置的初始化代码放入一个函数中,比如init()
,那么在您的回调中,您只需执行以下操作:
success: function(msg2){
$('#item-list2').append(msg2.txt);
// init draggable and droppable on replace elements
init();
}