jQuery操作JSF中的Checkbox树
下面的代码是,当选中父节点,则子节点全选;选中任意一个子节点,则选中父节点
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;
}
});
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.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 = true;
jQuery(parentDiv).contents().find(":checkbox").each(function() {
if(!this.checked) {
hasSelected = false;
}
});
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 ;
}
}
声明:此文章从
http://www.blogjava.net/TiGERTiAN/archive/2009/12/27/307463.html
转载过来的
分享到:
相关推荐
jQuery4jsf 是一个 JSF(JavaServer Faces)组件库,它使用了 jQuery javascript 框架的强大功能。 这些 JSF(JavaServer Faces) 组件具有 jQuery 的附加价值,它允许最终用户快速简单地实现其应用程序。
JSF中文教程JSF中文教程JSF中文教程JSF中文教程
JAVA Hibernate dom4j jquery jsf spring 各种API下载 CHM格式
jsf 中文文档jsf 中文文档jsf 中文文档jsf 中文文档
JSF Richfaces构建树实例 JSF Richfaces构建树
一些关于jsf组件树的动态添加,删除操作资料
精通JSF中文教程精通JSF中文教程精通JSF中文教程精通JSF中文教程精通JSF中文教程精通JSF中文教程
JSF中文文档
NULL 博文链接:https://sailinglee.iteye.com/blog/429696
jsf的中文教程chm版的和讲解jsf中使用到的一些参数的传递方式,学习jsf很不错的材料……
jsf中文使用教程jsf中文使用教程
有JSF框架的应用,以及操作的步骤写的很详细
jsf实例 JSF学习 JSF jar包 JSF jsf实例 JSF学习 JSF jar包 JSFjsf实例 JSF学习 JSF jar包 JSF jsf实例 JSF学习 JSF jar包 JSF
在未来的发展中,有可能所有的J2EE应用服务器都需要支持JSF。 Java Server Faces技术好处 引入了基于组件和事件驱动的开发模式,使开发人员可以使用类似于处理传统界面的方式来开发Web应用程序。提供了行为与...
Dhtml手册、 JSF中文教程、JSF API、struts2.0中文帮助手册.chm等等
jsf 分页 jsf 分页 jsf 分页 jsf 分页
JSF入门(中文pdf)
这里是jsf的tags的书籍。主要讲述jsf的用法。
JSF中文入门教程JSF中文入门教程JSF中文入门教程JSF中文入门教程
ajax4jsf中文用户指南,很全面。适合初学者