2014-02-19 50 views
0

我有複選框樹視圖,哪些需要禁用選定模式的前兩個複選框。我可以在checkedreadonly屬性的幫助下做到這一點,但我可以取消選中不是我的要求的複選框。需要禁用具有樹擴展的選定模式的特定複選框

注意:即使我嘗試使用checkeddisable屬性,如果我使用disable,它會摺疊它的子節點。

如何解決它。

的jsfiddle:http://jsfiddle.net/uU82C/14/

我嘗試代碼:

checkedreadonly

var completeTreeView ="<div id='treeview-id' class='css-treeview'><ul><li><input type='checkbox' id=GrandParent checked readonly/><label1 for='item-0'>Grand Parent</label1><ul><li><input type='checkbox' id='parent' checked readonly/><label2 for='item-0'>parent</label2>"; 

checkeddisable

var completeTreeView ="<div id='treeview-id' class='css-treeview'><ul><li><input type='checkbox' id=GrandParent checked disable/><label1 for='item-0'>Grand Parent</label1><ul><li><input type='checkbox' id='parent' checked disable/><label2 for='item-0'>parent</label2>"; 

請幫助出於此。

+0

檢查,如果這有助於。我只是使用jquery'prop'方法.http://jsfiddle.net/seelan/4DqXv/891/ – scarecrow

回答

1

在這裏我修改了你的樣本。希望它對你有所幫助。謝謝。

<!DOCTYPE HTML> 
<html> 
<head> 
<script src="http://code.jquery.com/jquery-latest.min.js"></script> 
<script>   
$(document).ready(function() { 
    $('input[name="level-1"],input[name="level-2"]').bind('click', function() { 
     $('input[type=checkbox]', $(this).parent('li')).attr('checked', ($(this).is(':checked'))); 
    }); 

    $('input[name="level-1"],input[name="level-2"]').change(function(e) { 
     $(e.target).prop({disabled:true}); 
    }); 

    $('input[name="level-1"],input[name="level-2"]').trigger('change'); 

}); 
</script> 
</head> 
<body> 
<ul> 
    <li> 
    <input type="checkbox" name="level-1">Grand Parent</input> 
    <ul> 
     <li> 
      <input type="checkbox" name="level-2">parent</input> 
      <ul> 
       <li> 
        <input type="checkbox" name="level-3">child 1</input> 
       </li> 
       <li> 
        <input type="checkbox" name="level-3">child 2</input> 
       </li> 
       <li> 
        <input type="checkbox" name="level-3">child 3</input> 
       </li> 
       <li> 
        <input type="checkbox" name="level-3">Level 3</input> 
       </li> 
      </ul> 
     </li> 
    </ul> 
    </li> 
</ul> 
</body> 
</html> 

Demo

+0

感謝您的發佈。不過這不是我的要求@Jeba。我的plm是盛大的父母,父母應該檢查默認,不應該被允許再次取消選擇。在你的例子中,我可以取消選擇節點。 – Hariharan

+0

@Hariharan,請檢查更新後的來源。它爲我工作很好。請檢查並讓我知道。謝謝。 – Jeba

+0

非常感謝Jeba。它工作正常,並按預期。 – Hariharan

相關問題