双击时打开对话框的问题

时间:2014-03-18 18:37:14

标签: javascript jquery html

当我在收件箱列表中添加卡片时,我可以在双击它时打开对话框。它工作正常。当我拖动卡并将其放入Onhold列表时,问题就来了。我试图双击打开对话框但没有成功。 解决方案的任何想法?

Demo

HTML:

<!--Wrapper div-->
    <div id="wrapper">
        <div id="onHoldList" class="cellContainer">
            <p>On Hold</p>
        </div>
        <!--Inbox list and button to add a card-->
        <div id="inboxList" class="cellContainer">
            <p style="display: inline">Inbox</p> 
            <!--Button to add a Card-->
            <input type="button" id="AddCardBtn" value="+ Add a Card..."/> <hr class="fancy-line"/> <br/>

            <!--Card div-->
            <div id="userAddedCard"> <br/>
                <div>

                </div>
            </div>
        </div>


    </div>
    <!--Modal Dialog-->
    <div id="modalDialog">

        <form>
            <label>Title</label>
            <input type="text" id="customTextBox" value="some value"/>
            <p>Date: <input type="text" id="datepicker" value="some date"/></p> 
            <input type="button" id="Getbtn" value="Get value"/> <hr/><br/>


        </form>

    </div>

JQuery的:

  $(function () {
    // Click function to add a card
    var $div = $('<div />').addClass('sortable-div'); 
    $('<label>Title</label><br/>').appendTo($div);              
    $('<input/>', { "type": "text","class":"ctb"}).appendTo($div);
    $('<input/>', { "type": "text","class":"date"}).appendTo($div);
    var cnt =0,$currentTarget;
    $('#AddCardBtn').click(function () {
      var $newDiv = $div.clone(true);
      cnt++;  
      $newDiv.prop("id","div"+cnt);  
      $('#userAddedCard').append($newDiv);
//      alert($('#userAddedCard').find("div.sortable-div").length);        
    });

    // Double click to open Modal Dialog Window
    $('#userAddedCard').dblclick(function (e) {
        $currentTarget = $(e.target);

        $('#modalDialog').dialog({
            modal: true,
            height: 600,
            width: 500,
            position: 'center'
        });
        return false;

    });
    $("#datepicker").datepicker({showWeek:true, firstDay:1});

    $("#Getbtn").on("click",function() {
      var val = $("#customTextBox").val();
      $currentTarget.find(".ctb").val(val);
      $currentTarget.find(".date").val($("#datepicker").val() );
      $('#modalDialog').dialog("close");
    });

     // Sortable cards
    $('.cellContainer').sortable({
        items: '.sortable-div',
        containment: 'document',
        cursor: 'crosshair',
        opacity: '0.70',
        connectWith: '.cellContainer',

    }).disableSelection();
});

1 个答案:

答案 0 :(得分:3)

Div移动到保留列表不再是#userAddedCard的孩子。

更改

$('#userAddedCard').dblclick(function (e) {

$('#wrapper').on('dblclick', '.sortable-div', function (e) {