JQUERY css类不适用于动态添加div
使用JQuery-1.6.2和拖放插件 以下是webform1.aspx中的代码JQUERY css类不适用于动态添加div,jquery,Jquery,使用JQuery-1.6.2和拖放插件 以下是webform1.aspx中的代码 $(document).ready(function() { $( ".draggable" ).draggable({ revert: "invalid" , helper: "clone" }); $( ".droppable" ).droppable({ activeClass: "ui-state-hover", hoverClass: "ui-state-
$(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 );
}
});
});
在drop中,我调用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>");
context.Response.Write(“”);
在从handler.ashx动态添加div时,当拖动对象时,droppable div css类应高亮显示,这不起作用或者您必须在success方法中绑定droppable-
$('.droppable').droppable(options);
您可以将选项设置为常量并仅定义一次
否则,您可以将live绑定到mouseenter或hover上的元素,在该元素处可以附加可拖放文件
$('.droppable').live('mouseenter',function() {
$(this).droppable(options);
});
您缺少分号,
var content=$(“.droppable”)
和ans\u type=$items.attr(“id”)
您可能正在查找$.live()
或$.delegate()
。