js operates CheckBoxList to achieve full selection/inverse selection (completed on the customer service side)_javascript skills
WBOY
Release: 2016-05-16 17:42:19
Original
1224 people have browsed it
For the CheckBoxList control, on the one hand, it is necessary to bind a large amount of data on the server side; on the other hand, it is often required to implement functions such as all selection and inverse selection. Although this aspect of the work can be done on the server side, it seems that such a simple task should be done on the client side.
Specific method: Put a CheckBoxList control in the page and add several items to analyze the HTML code it generates, so that you can use js to dynamically When controlling, it will be very clear that the test code is as follows:
Here, excerpt Part of the code, the blue part is what we care about. In HTML CheckBoxList generates many inputs (type is checkbox), and its ID is "CheckBoxList1_i" (i is a number). In this way, we only need to know a few items to easily control it with js. These inputs are included in a table with the id CheckBoxList1, so they can be passed:
This method gets how many items there are in CheckBoxList. The remaining work is actually It's very simple, just change the status of each checkbox through js. First add three buttons to achieve full selection, inverse selection and clear control, as shown below:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn