easyui tree帶checkbox實現(xiàn)單選的簡單實例
更新時間:2016年11月07日 10:03:44 投稿:jingxian
下面小編就為大家?guī)硪黄猠asyui tree帶checkbox實現(xiàn)單選的簡單實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
實例如下:
<ul id="regionTree"></ul>
$('#regionTree').tree({
cascadeCheck: false,
//onlyLeafCheck: true,
checkbox: true,
data: [{
"id": 1,
"text": "My Documents",
"children": [{
"id": 11,
"text": "Photos",
"state": "closed",
"children": [{
"id": 111,
"text": "Friend"
}, {
"id": 112,
"text": "Wife"
}, {
"id": 113,
"text": "Company"
}]
}, {
"id": 12,
"text": "Program Files",
"children": [{
"id": 121,
"text": "Intel"
}, {
"id": 122,
"text": "Java",
"attributes": {
"p1": "Custom Attribute1",
"p2": "Custom Attribute2"
}
}, {
"id": 123,
"text": "Microsoft Office"
}, {
"id": 124,
"text": "Games",
"checked": true
}]
}, {
"id": 13,
"text": "index.html"
}, {
"id": 14,
"text": "about.html"
}, {
"id": 15,
"text": "welcome.html"
}]
}]
,
width: 160,
height: 32,
panelHeight: 400,
onSelect: function (node) {
var cknodes = $('#regionTree').tree("getChecked");
for (var i = 0; i < cknodes.length; i++) {
if (cknodes[i].id != node.id) {
$('#regionTree').tree("uncheck", cknodes[i].target);
}
}
if (node.checked) {
$('#regionTree').tree('uncheck', node.target);
} else {
$('#regionTree').tree('check', node.target);
}
},
onLoadSuccess: function (node, data) {
$(this).find('span.tree-checkbox').unbind().click(function () {
$('#regionTree').tree('select', $(this).parent());
return false;
});
}
})
關鍵代碼:
onSelect: function (node) {
var cknodes = $('#regionTree').tree("getChecked");
for (var i = 0; i < cknodes.length; i++) {
if (cknodes[i].id != node.id) {
$('#regionTree').tree("uncheck", cknodes[i].target);
}
}
if (node.checked) {
$('#regionTree').tree('uncheck', node.target);
} else {
$('#regionTree').tree('check', node.target);
}
},
onLoadSuccess: function (node, data) {
$(this).find('span.tree-checkbox').unbind().click(function () {
$('#regionTree').tree('select', $(this).parent());
return false;
});
}
以上這篇easyui tree帶checkbox實現(xiàn)單選的簡單實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
Javascript動態(tài)綁定事件的簡單實現(xiàn)代碼
Javascript事件綁定的方法很多,很靈活。不過,作為比較簡單的動態(tài)綁定,下面的代碼看似正確,但得不到預期的效果。2010-12-12
JavaScript實現(xiàn)帶播放列表的音樂播放器實例分享
這篇文章主要介紹了JavaScript實現(xiàn)帶播放列表的音樂播放器實例分享,包括對播放完歌單之后沒有將要播放的歌曲的提示功能,需要的朋友可以參考下2016-03-03
Javascript連接數(shù)據(jù)庫查詢并插入數(shù)據(jù)
這篇文章主要介紹了Javascript連接數(shù)據(jù)庫查詢并插入數(shù)據(jù),下面文章圍繞主題展開詳細內(nèi)容,具有一的參考價值,需要的小伙伴可以參考一下,希望對你的學習有所幫助2022-03-03
JavaScript針對網(wǎng)頁節(jié)點的增刪改查用法實例
這篇文章主要介紹了JavaScript針對網(wǎng)頁節(jié)點的增刪改查用法,實例分析了JavaScript操作網(wǎng)頁節(jié)點的技巧,非常具有實用價值,需要的朋友可以參考下2015-02-02

