2011-10-09 108 views
0

使用jQuery-1.6.2和拖放插件JQUERY CSS類無法正常工作的動態添加DIV

下面是WebForm1.aspx的

$(document).ready(function() { 
    $(".draggable").draggable({ revert: "invalid" , helper: "clone" }); 

    $(".droppable").droppable({ 
     activeClass: "ui-state-hover", 
     hoverClass: "ui-state-active", 
     drop: function(event, ui) { 
      addFields(ui.draggable); 
     } 
    }); 

}); 

碼上落我打電話addfields函數,它是如下

function addFields($items) 
{ 
    var content=$(".droppable") 
    ans_type=$items.attr("id") 
    i= parseInt(document.getElementById('txtQCnt').value); 
    document.getElementById('txtQCnt').value=i+1; 
    $.ajax 
    (
     { 
      url:'handler.ashx?ans_type='+ans_type+'&cnt='+document.getElementById('txtQCnt').value, 
      dataType:'html', 
      success: function(data) 
      { 
       var i; 
       content.append(data); 
      } 
     } 
    ) 
} 

handler.ashx的元素添加到頁面

context.Response.Write("<div id='"+objId+"' class='droppable'></div>"); 

上動態地從handler.ashx添加DIV,當被拖拽的對象可放開DIV + CSS類應該強調,這是不工作

+0

你缺少分號,'VAR含量= $( 「可棄 」)'和'ans_type = $ items.attr(「 ID」)' – rlemon

+0

您可能正在尋找'$ .live()'或'$ .delegate()'。 –

回答

0

要麼你已經綁定成功方法內可放開 -

$('.droppable').droppable(options); 

您可以將選項設置爲常量並只定義一次。

否則,您可以實時綁定到元素的mouseenter或懸停在其可放開可以連接。

$('.droppable').live('mouseenter',function() { 
    $(this).droppable(options); 
});