[英]jquery ui sortable append
here is my jquery code as it stands. 这是我的jQuery代码。
$(document).ready(function() {
$('#btn1').click(function() {
$("ol").append("<li>"+$("#txt1").val()+"</li>");
$("#txt1").val("").focus();
$('li').addClass('block2');
$('li').click(function() {
$(this).hide(500, function() {
$(this).remove('li');
});
});
});
});
Its basically a blank todo list, however when you enter in text and click the button, it appends to the list. 它基本上是一个空白的待办事项列表,但是当您输入文本并单击按钮时,它将追加到列表中。 I'm looking for code to re-arrange the items in the list 'that have been appended'.
我正在寻找代码来重新排列“已添加”列表中的项目。 All the examples for jquery-ui for sort-able or drop-able, all have 'li' elements already in place in the HTML so this will not work in my code.
jquery-ui的所有可排序或可删除示例均在HTML中具有“ li”元素,因此在我的代码中不起作用。
How do I add to my jquery code to make a user entered list rearrangable? 如何添加到我的jquery代码中以使用户输入的列表可重排?
You can do this by recalling sortable()
inside the first .click()
, like so: 您可以通过在第一个
.click()
调用sortable()
来实现此目的,如下所示:
$(document).ready(function() {
$('#btn1').click(function() {
$("ol").append("<li>"+$("#txt1").val()+"</li>");
$("#txt1").val("").focus();
$('li').addClass('block2');
$('ol').sortable();
$('li').click(function() {
$(this).hide(500, function() {
$(this).remove('li');
});
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.