我使用的是jquery-ui可排序交互。我想有一个复选框,当它被选中时禁用可排序交互。列表顺序和复选框状态都存储在mysql数据库中,使用php代码动态加载,并使用ajax更新。下面的代码适用于所有内容,除了列表的可排序状态与页面首次加载时的复选框状态不匹配。第一次选中复选框后,一切正常。php变量$items是一个保存列表的对象,$lock保存“选中”或“未选中”。
<head>
<script>
$(function() {
$("#sortable").sortable({stop:function(i) {
$.post('/index.php/welcome/process_sort', $("#sortable").sortable("serialize"))
}})
});
</script>
<script>
$(function() {
$("#disabler").change(function() {
if (this.checked) {
$("#sortable").sortable( "option", "disabled", true );
} else {
$("#sortable").sortable("option", "disabled", false);
}
})
});
</script>
</head>
<body>
<input type="checkbox" id="disabler" value="disabler" <?php echo $lock ?> >disable<br> </input>
<ul id="sortable">
<?php
foreach ($item as $row) {
$my_id = "id_".$row->id_items;
$my_text = $row->text;
?>
<li id=<?php echo"$my_id" ?> name=<?php echo"$my_id" ?> value=<?php echo "$my_text"?> class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"> </span><?php echo "$my_text"?></li>
<?php
}
?>
</ul>
</body> 我尝试添加一个包含jquery if块的$(.ready)文档函数,但它破坏了可排序的交互。
发布于 2012-11-17 19:03:56
试试这样的东西
<script>
$(function() {
$("#disabler").change(function() {
if (this.checked) {
$("#sortable").sortable( "option", "disabled", true );
} else {
$("#sortable").sortable("option", "disabled", false);
}
})
checkDisable();
});
function checkDisable(){
if($("#isAgeSelected").is(':checked')){
$("#sortable").sortable( "option", "disabled", true );
}
else {
$("#sortable").sortable("option", "disabled", false);
}
}
https://stackoverflow.com/questions/13427888
复制相似问题