In a program, a checkbox lsit is often used to render the number. Allows users to select multiple items. This blog post insus.net exercises the checkbox list related features, the effect shows as follows:
The following is the implementation process, first creating a model under the MVC application:
Create a new solid entity as the data source for the checkbox list:
Create a view method with the data source on the controller:
Here's how to create a view:
A div tag is used to dynamically load the checkbox list, and there are 8 ammonium buttons to implement the checkbox list related features in the future.
Here is a JS library that references jquery with a custom method function:
Now we can dynamically generate a checkbox list with jquery based on the data source written above:
The Ammonium button 1 event, clearing all selected options, is considered to be initialization.
The Ammonium button 2 event, gets the index of the selected option, which is calculated starting from 0.
The Ammonium button 3 event is the key value that gets the selected option.
The Ammonium button 4 event is the text that gets the selected option.
The Ammonium button 5 event is a multi-select list of checkbox lists for all selections.
The Ammonium button 6 event, which is the selection of the multi-select list, is reversed, the selected change uncheck, and the original is uncheck, changed to checked.
The Ammonium button 7 event is the option for the multi-select list and the even option is selected.
Ammonium Button 8 Event: