2014-03-13 6 views
0

받은 편지함 목록에 카드를 추가하면 카드를 두 번 클릭하면 대화 상자 창이 열립니다. 대화 상자 창에서 캘린더에서 날짜를 선택하고 입력 필드에 문자열 값을 입력하고 동적 확인란을 만들 수 있습니다. 그런 다음 버튼 (Get Value)을 누르면 값이 카드에 표시됩니다. 이것은 잘 작동합니다. 문제는받은 편지함에 다른 카드를 추가하고 두 번 클릭하여 대화 상자 창을 열면 이전 대화 상자 창과 같은 값이 표시됩니다. 나는 그것을 원하지 않는다. 새 카드를 추가 할 때마다 한 번 더 클릭하면 대화 상자 창에 값이 표시되지 않습니다.카드에 고유 한 대화 상자를 만드는 방법

솔루션이 카드를 고유하게 만들 수 있다고 생각하지만 확실하지 않습니다.

도와주세요. 일부 코드를 제공해주세요.

DEMO

HTML :

<!--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/> 

     <label>Add checkBox</label> 
     <br /> 
     <div id="progressbar"></div> 
     <br /> 
     <input type="text" id="checkBoxName" /> 
     <input type="button" id="btnSaveCheckBox" value="_Ok" /> 
     <br /> 

    </form> 

</div> 
<!--Reference to Jquery--> 

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); 

    }); 

    // 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"); 
    }); 

    // Add a new checkBox 
    $('#btnSaveCheckBox').click(function() { 
     addCheckbox($('#checkBoxName').val()); 
     $('#checkBoxName').val(""); 
    }); 

    function addCheckbox(name) { 
     var container = $('#modalDialog'); 
     var inputs = container.find('input'); 
     var id = inputs.length + 1; 

     $('<input />', { type: 'checkbox', id: 'cb' + id, value: name }).appendTo(container); 
     $('<label />', { 'for': 'cb' + id, text: name }).appendTo(container); 
     $('<br/>').appendTo(container); 


    }  
}); 
+0

"도와주세요. 그리고 약간의 코드를 제공하십시오.".. 우리는 당신을 위해 약간의 코드를 제공하지 않습니다. 그것에 대해 배워야합니다. 코드를 묻는 것은 항상 나쁜 습관입니다. –

+0

나는 내 자신을 시험해 보았지만 어떻게해야할지 모른다. 나는 코드를 요구하는 것이 항상 나쁜 습관이라는 것에 동의하지 않는다. 나는 항상 무언가를 배웁니다. – AdiT

+0

문제를 해결할 생각이 있습니까 ?? – AdiT

답변

0
for your code add the lines that i added 
$(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()); 
    document.getElementById('customTextBox').value="";//add this line 
    document.getElementById('datepicker').value="";//add this line 
    $('.allcheckbox').remove();//add this line 
    $('#modalDialog').dialog("close"); 
}); 

// Add a new checkBox 
$('#btnSaveCheckBox').click(function() { 
    addCheckbox($('#checkBoxName').val()); 
    $('#checkBoxName').val(""); 
}); 

function addCheckbox(name) { 
    var container = $('#modalDialog'); 
    var inputs = container.find('input'); 
    var id = inputs.length + 1; 

    $('<input />', { type: 'checkbox', class: 'allcheckbox', id: 'cb' + id, value: name }).appendTo(container);//add the attribute class 
    $('<label />', { 'for': 'cb' + id, class: 'allcheckbox', text: name }).appendTo(container);//add the attribute class 
    $('<br/>').appendTo(container); 


}  

});

+0

나는 여전히 같은 문제가 있습니다. – AdiT

+0

당신이 내가 언급 한 줄을 추가 했습니까? 잘하고 있습니다 ... –

+0

오, 내 잘못입니다. 미안, 못 봤어. 원하는 카드를 두 번 클릭하고 캘린더에서 날짜를 선택하면 입력 필드에 문자열 값을 입력하고 동적 확인란을 만듭니다. 그런 다음 대화 상자를 닫은 후 같은 카드를 두 번 클릭하면이 대화 상자에 동일한 값이 표시되기를 원하지만 문제는 두 번 클릭했을 때 비어 있다는 것입니다. 나중에 새 카드를 추가 할 때 대화 상자가 비어 있어야합니다. 내가 무슨 말하는지 이해 하겠니? – AdiT

관련 문제