Enjoy yourself,and don't care about others' thinking!
----TiGERTiAN
BlogJava
首頁
新隨筆
聯系
聚合
管理
隨筆-348 評論-598 文章-0 trackbacks-0
用jQuery給頁面中樹形的Checkbox默認加上父子節點相關操作(JSF的Richfaces專用)
jQuery.noConflict();
//
與JSF搭配需要這句話,不然會有沖突
jQuery(document).ready(
function
()
{
//
Add click event listener to each checkbox in the tree page
//
Note! Using this simple selector assumes that there are no other
//
checkboxes on the page, if there are other checkboxes then
//
selector should be changed
jQuery(
"
:checkbox
"
).click(
function
()
{
updateChildren(
this
);
updateParent(
this
);
}
);
}
);
</
script
>
<
script type
=
"
text/javascript
"
>
function
updateChildren(currentCheckBox)
{
//
Get state of current checkbox (true or false)
var
state
=
currentCheckBox.checked;
//
Get parent TABLE, where current checkbox is places
var
parentTables
=
jQuery(currentCheckBox).parents(
"
table
"
);
var
parentTable
=
parentTables[
0
];
//
Get DIV where child nodes with checkboxes are situated
//
See http://docs.jquery.com/Traversing/ to get better uderstanding of
//
parents() and next()
var
childDivs
=
jQuery(parentTable).next(
"
div
"
);
if
( childDivs.length
>
0
)
{
var
childDiv
=
childDivs[
0
];
//
Iterate over all child nodes checkboxes and set same state as the
//
current checkbox state
jQuery(childDiv).contents().find(
"
:checkbox
"
).each(
function
()
{
this
.checked
=
state;
}
);
}
}
//
更新父節點的方法,如果子節點全部選中則父節點選中,如果子節點中有一個未選中,則父節點也未選中
function
updateParent(currentCheckbox)
{
var
parentDivs
=
jQuery(currentCheckbox).parents(
"
div
"
);
var
parentDiv
=
parentDivs[
0
];
var
hasSelected
=
false
;
jQuery(parentDiv).contents().find(
"
:checkbox
"
).each(
function
()
{
if
(
this
.checked)
{
hasSelected
=
true
;
}else{
hasSelected =
false
;
return;
}
}
);
var
parentTables
=
jQuery(parentDiv).prev(
"
table
"
);
if
(parentTables.length
>
0
)
{
var
parentTable
=
parentTables[
0
];
var
parentCheckboxes
=
jQuery(parentTable).find(
"
:checkbox
"
);
var
parentCheckbox
=
parentCheckboxes[
0
];
parentCheckbox.checked
=
hasSelected ;
}
}
注意引入jQuery包。
此js代碼加到頁面中,將會給頁面中的樹形菜單的Checkbox默認加上一些功能:當選擇父節點時全選子節點;當子節點全選時,父節點也會被自動選擇上。同時不會影響其他Checkbox。
---------------------------------------------------------
專注移動開發
Android, Windows Mobile, iPhone, J2ME, BlackBerry, Symbian
posted on 2009-11-12 08:46
TiGERTiAN
閱讀(3432)
評論(4)
編輯
收藏
所屬分類:
VB/ASP
、
JSF
評論:
#
re: 用jQuery給頁面中樹形的Checkbox默認加上父子節點相關操作 2009-11-12 14:30 |
凡客誠品優惠券
不錯,收藏
回復
更多評論
#
re: 用jQuery給頁面中樹形的Checkbox默認加上父子節點相關操作 2009-11-12 18:49 |
BeanSoft
收藏了!
回復
更多評論
#
re: 用jQuery給頁面中樹形的Checkbox默認加上父子節點相關操作 2009-11-12 19:25 |
jackyrong
能否提供完整代碼下載呢
回復
更多評論
#
re: 用jQuery給頁面中樹形的Checkbox默認加上父子節點相關操作
2009-11-12 19:45 |
TiGERTiAN
@jackyrong
這個就是完整的代碼啊
回復
更多評論
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
相關文章:
用jQuery給頁面中樹形的Checkbox默認加上父子節點相關操作(JSF的Richfaces專用)
Oracle數據遷移到SQL Server小結
asp導出excel用到的類
VML 3D報表修正版
最近在幫學校做網站
ASP中遇到的問題
ASP防注的最佳的方法(我認為的)
專注移動開發--Windows Mobile, Android, iPhone, J2ME, BlackBerry, Symbian, Windows Phone
慢慢混,慢慢學
<
2009年11月
>
日
一
二
三
四
五
六
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(43)
給我留言
查看公開留言
查看私人留言
隨筆分類
(402)
Ajax(4)
Android(58)
BlackBerry(8)
C/C++(3)
Design Patterns(6)
Discuz!NT(1)
DotNet(26)
Feeling(61)
Flex(4)
Grails(2)
Hibernate(1)
iPhone(5)
J2ME(11)
Java(99)
JSF(26)
Linux(18)
MapXtreme(9)
Objective c(1)
Oracle(6)
Other technique(20)
Perl/Python(1)
Roller (10)
Symbian
VB/ASP(7)
WebWork(3)
Windows Mobile(10)
WindowsPhone(2)
隨筆檔案
(306)
2017年5月 (1)
2016年8月 (1)
2015年11月 (1)
2015年2月 (1)
2015年1月 (1)
2013年12月 (1)
2013年5月 (1)
2013年4月 (1)
2012年9月 (1)
2012年7月 (1)
2012年6月 (1)
2012年5月 (2)
2012年4月 (1)
2012年2月 (2)
2012年1月 (1)
2011年11月 (2)
2011年10月 (1)
2011年9月 (1)
2011年8月 (2)
2011年7月 (3)
2011年6月 (2)
2011年3月 (3)
2011年2月 (4)
2011年1月 (15)
2010年12月 (1)
2010年11月 (2)
2010年10月 (6)
2010年9月 (12)
2010年8月 (3)
2010年7月 (2)
2010年6月 (6)
2010年5月 (14)
2010年4月 (7)
2010年3月 (16)
2010年2月 (10)
2010年1月 (14)
2009年12月 (12)
2009年11月 (5)
2009年10月 (3)
2009年9月 (2)
2009年8月 (3)
2009年6月 (1)
2009年4月 (2)
2009年3月 (2)
2009年1月 (3)
2008年12月 (3)
2008年11月 (20)
2008年10月 (17)
2008年9月 (3)
2008年4月 (1)
2008年3月 (2)
2008年2月 (8)
2008年1月 (1)
2007年11月 (2)
2007年10月 (13)
2007年9月 (3)
2007年7月 (4)
2007年6月 (2)
2007年5月 (12)
2007年4月 (15)
2007年3月 (6)
2007年2月 (2)
2007年1月 (1)
2006年7月 (2)
2006年4月 (1)
2006年1月 (1)
2005年11月 (1)
2005年8月 (1)
2005年7月 (9)
相冊
我正在讀的書
我的好友們
JavaBy
有心就有翼 有夢就會飛--MC
搜索
積分與排名
積分 - 812997
排名 - 50
最新評論
1.?re: Hibernate三種狀態的區分,以及save,update,saveOrUpdate,merge等的使用[未登錄]
哈哈~
--a
2.?re: onInterceptTouchEvent和onTouchEvent調用時序
@米其林的微笑
在你的子view重寫ontouchevent方法就行
--kxt
3.?re: Android彈出撥號界面和撥打電話實現
這找不到call是怎么回事?現在有別的方法實現這個功能嗎?
--firetomato
4.?re: Android彈出撥號界面和撥打電話實現
請我dial和call方法有什么區別么?
--jaime
5.?re: Android文字跑馬燈控件(文本自動滾動控件)
如何讓滾動的速度快一點啊??
--學鳥
閱讀排行榜
1.?onInterceptTouchEvent和onTouchEvent調用時序(38719)
2.?Android的Intent和IntentFilter應用說明一例(37716)
3.?Hibernate三種狀態的區分,以及save,update,saveOrUpdate,merge等的使用(34354)
4.?Android中短信攔截解決方案(31106)
5.?Android中ContentProvider和ContentResolver使用入門(21435)
評論排行榜
1.?【JSF】Richfaces復選框樹(Checkbox tree)的權限分配的解決方案(69)
2.?JSF中動態生成HtmlMessage控件出錯的解決辦法(38)
3.?hibernate中at org.hibernate.tuple.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:372)異常的解決方法(27)
4.?這兩天用Flex寫了一個多媒體播放器(19)
5.?Android文字跑馬燈控件(文本自動滾動控件)(17)
Powered by:
博客園
模板提供:
滬江博客
Copyright ©2025 TiGERTiAN
主站蜘蛛池模板:
贞丰县
|
延寿县
|
陈巴尔虎旗
|
新干县
|
塘沽区
|
南涧
|
泸水县
|
云和县
|
石屏县
|
治县。
|
白河县
|
滦平县
|
乌拉特中旗
|
金坛市
|
集安市
|
五莲县
|
麻栗坡县
|
新竹县
|
浮山县
|
清涧县
|
元阳县
|
治县。
|
射阳县
|
托克逊县
|
满洲里市
|
尼木县
|
巴彦县
|
富民县
|
临湘市
|
巩义市
|
鄂伦春自治旗
|
全州县
|
新巴尔虎左旗
|
蓬莱市
|
镇原县
|
泰州市
|
金堂县
|
张北县
|
沭阳县
|
太仆寺旗
|
汨罗市
|