[英]Generated html code with javascript not working with jquery sortable
每当用户按下按钮时,我都会生成一个表格。 生成的表应该是可排序的,尽管jquery的sortable仅在服务器端生成的表上有效。
生成表:
<script>
$(document).on('click', '.addMenu', function() {
$('.empty-table').after('<table class="account-subheader"><tbody class="connectedSortable"><tr><td colspan=5></td></tr></tbody> </table>');
//$(".empty-table").append($(".account-subheader"));
});
</script>
可排序功能:
<script>
$(document).ready( function() {
$( ".connectedSortable" ).sortable({
connectWith: ".connectedSortable",
receive: function(event, ui) {
$.ajax({
// Some ajax calls
},
success: function(response) {
if (response.status == "success") {
console.log(response);
} else {
console.log(response);
}
}
});
}
}).disableSelection();
});
</script>
您需要在生成HTML之后调用sortable
函数。 尝试将sortable
函数保留在javascript方法内, click
从document.ready
和click
事件中调用该方法。
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.