Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the cascade selection of treeview by jquery

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is about how jquery implements cascading options for treeview. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The use of jquery.treeview is very simple, copy the treeview style file and js into the corresponding project directory first, it should be noted that the p_w_picpaths file and jquery.treeview.css in the same directory, of course, you can also directly modify the path in the css style.

$(document) .ready (function () {$("# jqTree") .treeview ({animated: "fast", persist: "location", collapsed: true, unique: true});})

An example of a directory tree is as follows:

Level 1, level 1, level 2, level 3, level 4, level 4, level 1. Level 4, level 2, level 4, level 4

The key js code is the cascade operation. When I select a node, I should select the corresponding child node and ancestor node accordingly. When I cancel the selection, I should first judge whether there are any selected items under the ancestor node, and if so, I should also cancel the selection of the ancestor node.

Click (function () {/ / descendant directory var c = $(this). Parent (). Find ("input"); var b = $(this) .attr ('checked'); $(this) .attr (' checked', b); c.each (function () {$(this) .attr ('checked', b);}) / / ancestral directory var count = 0; var p = $(this) .ancestor ('li'); / / all ancestral directories p.each (function (I) {if (itemized ancestor directory 0) {} else {var o = $(this). Find (' input'); if (count) {o [0] .ancestor = true } else {o [0] .requests = false;}} var ulChildren = $(this) .parent ('ul'). Find (' input'); count = 0; ulChildren.each (function () {if ($(this) .attr ('checked')) {count++ / / the number of parents of the current node selected}}); Thank you for reading! This is the end of this article on "how to realize the cascade choice of treeview in jquery". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report