我想你想循環遍歷元素並將每個單獨發佈到數據庫。在您的服務器方法返回一個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