這裏是a working example
在您的代碼,改變你的handleCardDrop()
功能是這樣的:
function handleCardDrop(event, ui) {
if($(this).children('.drag').length <2){
$(ui.draggable).css({"top": "1px" ,"left": 0 }).appendTo(this);
var apptValue = dataAppt.attr("data-appt");
apptValue -= 1;
dataAppt.attr("data-appt", apptValue);
if(($(this).attr("data-appt")) == 1){
$(this).attr("data-appt","2");
}
else{
$(this).attr("data-appt","1");
}
ui.draggable.draggable('option', 'revert', false); // move this outside the if/else so it gets applied in all cases
resetAppointment();
}
else{
alert('Only Two allowed!!!');
}
}
此外,改變你的resetAppointment()
功能是這樣的:
function resetAppointment(){
$('td[data-appt="2"] .drag').css("width", "45%"); // 45% not 50% since your full witdh elements are only 90% not 100%
var width = $('td[data-appt="2"] .drag').first().width();
$('td[data-appt="2"] .drag').last().css({"left": width}); // wrap your selector string with single quotes and use double quotes inside where needed so you dont have to escape the quotes
$('td[data-appt="1"] div.drag').css({"width": "90%", "left" : "0px"}); // i use px explicitly here because if I dont, I'll always forget to add it later when I change this to 10 or something
}
非常感謝你.. 。你很棒... :) :) – SiVi 2015-03-09 04:40:09
但是'$(this).draggable('option','revert',false);'這應該是'true'我忘記輸入'$(this) .draggable('option','revert',false); 'handleDrop()函數的else部分中的這段代碼... – SiVi 2015-03-09 04:48:02
啊,是的,移動'ui.draggable.draggable('option','revert',false);'if/else之外,所以它被應用於所有情況都解決了這個問題。我更新了這個例子和我的答案。很高興幫助:) – DelightedD0D 2015-03-09 05:27:34