题
我试图创建一个页面,用户可以在该页面上搜索页面左侧的项目,并将其拖放到右边的项目,就像购物车一样。
我一直在使用
$(function() {
$(".result").draggable({
helper: function(event, ui) {
return $(this).clone().children("img");
}
});
$("#rightcol").droppable({
accept: ".result",
drop: function(event,ui){
$(this).append($(ui.draggable).clone());
//console.log($(ui.draggable));
}
});
});
对于有效的拖放方式,我希望的是,但是当提交新的搜索时,用户拖到右侧(#RightCol)的任何东西都会丢失。我尝试将表格提交更改为与这样的jQuery使用Ajax
$(document).ready(function() {
$("#form").submit( function () {
$.post(
'p_search.php',
$(this).serialize(),
function(data){
//data is what i want to be draggable
//call other function here
$(".build").html(data).load();
}
);
return false;
});
});
效果很好,但是divs(.result)不可拖动。有没有办法可以轻松初始化(.result)元素而不刷新页面?
解决方案
我相信它们不可拖动,因为它们是创造的 后 您已经定义了哪些项目是可拖动的。
(意思是 - 它们在 $(".result").draggable(...
称呼。)
我想你应该看看 居住()
不隶属于 StackOverflow