Home >
Article > Web Front-end > js operates CheckBoxList to achieve full selection/inverse selection (completed on the customer service side)_javascript skills
js operates CheckBoxList to achieve full selection/inverse selection (completed on the customer service side)_javascript skills
WBOYOriginal
2016-05-16 17:42:191234browse
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:
자, 이제 IE 테스트를 통해 백그라운드에서 바인딩 작업을 할 수 있고, 모두 선택 등의 보조 기능도 자유롭게 사용할 수 있게 되었습니다!
Statement:
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