我正在做jquery draggable它在初始情况下工作正常但是当使用jswhat创建一个新的相同div时它不起作用我的代码的实际问题请帮助我 http://galtech.org/testing/drag_new.php 拖我老做得很好 但是使用New元素创建了新的可拖动div(底部是红色锚点) 它没有可拖动的属性
<script>
function shw()
{
$("#name").html('<div id="draggable">Drag me new</div>');
}
$(document).ready(function() {
$( "#draggable" ).draggable({ cursor: 'move', containment: '#name', opacity: 0.35 });
});
</script>
</head>
<body >
<div id="name" style="background:#9999FF; height:500px; width:500px;">
<div id="draggable">Drag me old</div>
</div>
<a onClick="shw();" style="background-color:#FF0000; cursor:pointer;">New element</a>
</body>
</html>
答案 0 :(得分:1)
您必须重新初始化可拖动的。制作document.ready中的内容并在添加新的可拖动
后调用它答案 1 :(得分:0)
答案 2 :(得分:0)
<script> function shw() { $("#name").html('<div id="draggable">Drag me new</div>'); } $(document).ready(function() { $( "#draggable" ).draggable({ cursor: 'move', containment:
'#name',不透明度:0.35});
}); </script>
添加新元素后初始化可拖动
function shw() {
$("#name").html('<div id="draggable">Drag me new</div>')
.find('#draggable').draggable({ cursor: 'move', containment:'#name',opacity: 0.35});
}
$(document).ready(function() {
$( "#draggable" ).draggable({ cursor: 'move', containment:'#name',opacity: 0.35});
});