【问题标题】:draggable element should go to the start position on confirmation false可拖动元素应在确认错误时到达起始位置
【发布时间】:2014-09-15 05:29:29
【问题描述】:

我的代码如下。

function editState()
{
 var b  = confirm("Are you sure?");
 $( ".usMainDef" ).draggable({
        appendTo: "body",
        revert:true,
        stack: ".usMainDef"
        });

        $('.inproUS').droppable(
            {

                activeClass: "ui-state-default",
                hoverClass: "ui-state-hover",
                accept: ".usMainDef",
                drop: function( event, ui ) {
                    if (!b) {

                            } else {
                        id= $(ui.draggable).prop('id');
                        var colid=$(event.target).attr('id');
                        var newid=parseInt(id);
                        $( "<div id='"+id+"' class='box usMainInp' ></div>" ).html( ui.draggable.html() ).appendTo( this).draggable( {cursor: 'move', revert:'invalid' });

                        $.ajax({
                            type: "POST",
                            url: "index.php?r=workspace/changeState",
                            // The key needs to match your method's input parameter (case-sensitive).
                            data: {
                                uState:colid,
                                uID:newid

                            },
                            dataType: "json",
                            success: function(data){

                            },
                            failure: function(errMsg) {
                                alert(errMsg);
                            }
                        });
                    }

                }
            });
    }

当我拖动具有“usMainDef”类的元素时,它会提示确认。如果我点击“取消”,我想回到之前的位置。如果我点击“确定”,它应该发送 ajax 请求。后面的部分正在工作。我的问题是当我单击“取消”元素时不会移动到它的起点。我该怎么做?

【问题讨论】:

    标签: jquery ajax draggable droppable confirmation


    【解决方案1】:

    我终于得到了答案。 这里是。我只想添加以下几行。然后它工作得很好。

    if (!confirm("Are you sure?")) {
                        ui.draggable.animate(ui.draggable.data().origPosition,"slow");                          
                    }
    
    else
        {
    /*ajax request*/
    }
    

    【讨论】:

      猜你喜欢
      • 2021-03-27
      • 1970-01-01
      • 2011-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-30
      • 2023-02-02
      相关资源
      最近更新 更多