我<ul>
通过使用动态设置我的innerHTMLdocument.getElementById("myUL").innerHTML="<li...>
我动态创建的<li>
不能被 jquery 拖动。然而,静态 HTML 是。
如何使使用 innerHTML 指令创建的新创建的动态 HTML 可拖动?
这是一些代码:
function onAddTask() {
var task = document.getElementById("task").value;
for (i = 0; i < MAX_TASKS; i++) {
if (tasks[i] == null) {
tasks[i] = task;
break;
}
}
/* construct HTML */
var html = "<li class='ui-widget-content ui-corner-tr'>" +
"<h5 class='ui-widget-header'>New Task</h5>" +
"<a href='' onclick='return onCreateTask();'><img src='graphics/newtask.png' width='96' height='72'/></a>" +
"<center>Create a new task</center>" +
"</li>";
for (i = 0; i < MAX_TASKS; i++) {
if (tasks[i] != null) {
html += "<li class='ui-widget-content ui-corner-tr ui-draggable' style='width: 96px; display: list-item;'><h5 class='ui-widget-hea
+ "<img src=graphics/task.png width=96 height=72>"
+ tasks[i]+"</li>";
}
}
var todoList = document.getElementById("todo");
todoList.innerHTML = html;
tb_remove();
return false;
}
然后在我的 HTML 中
<body>
<ul id="todo" class="todo ui-helper-reset ui-helper-clearfix">
<li class='ui-widget-content ui-corner-tr ui-draggable' style='width: 96px; display: list-item;'><h5 class='ui-widget-header'>blah</h5>
<img src=graphics/task.png width=96 height=72>
</li>
<li class="ui-widget-content ui-corner-tr">
<h5 class="ui-widget-header">New Task</h5>
<a href="" onclick='return onCreateTask();'><img src="graphics/newtask.png" width="96" height="72"/></a>
<center>Create a new task</center>
</li>
<li class="ui-widget-content ui-corner-tr">
<h5 class="ui-widget-header">Task</h5>
<img src="graphics/task.png" width="96" height="72" />
<center>Task Data</center>
</li>
</ul>