我想你想循环遍历元素并将每个单独发布到数据库。在您的服务器方法返回一个JSON对象,你可以用它来找到elment在页面上更新的类
$(".droppable").each(function(index, item){
var id = $(item).attr("id"); //server will pass this back so you can select it later
var height = $(item).css("height");
var width = $(item).css("width");
// etc.
$.ajax({
url: "test.html",
data: {id: height: height, width: width}, //add each property
success: function(data){ //data is returned by your server method
$(data.elementId).addClass("done"); //you passed elementId to the server as 'id'
}
});
});
,如果你想这样做的一个要求,你可以建立一个关联数组并传递。这里已经很晚了,这已经不在我的头顶了。这可能不是确切的语法,但希望它会指向你在正确的方向
var elements = new Array();
$(".droppable").each(function(index, item){
var id = $(item).attr("id"); //server will pass this back so you can select it later
var height = $(item).css("height");
var width = $(item).css("width");
// etc.
var item = { id: id, height: height, width: width };
elements.push(item); //an array of objects
});
$.ajax({
url: "test.html",
data: {elements: elements}
success: function(data){ //data is returned by your server method
// set the class on success
}
});
谢谢!!!!! – Sebastien