Home >Backend Development >PHP Tutorial >Study notes for javascript all selection effect_PHP tutorial
The effect I want to do is to automatically select all checkboxes when we open the page. The principle is: first get all the elements of type 'input', and then add a click event to each selected option. If all options are selected, the 'checked' attribute of each element becomes true through looping, otherwise it becomes false.
document.getElementById(' ') is the id attribute of an element to get an The specified element is returned as an object. document.getElementById(' ') obtains the control object based on the control TAG (type attribute) and returns an object array;
To achieve a select-all effect, you must first define a set of options.
The code is as follows | Copy code | ||||
Select all
|
代码如下 | 复制代码 |
The code is as follows | Copy code |
Personally, I feel that this method is still lacking. It will select all input types on the page. Now we have written a method that uses click events to select all and inverse the selection effect.
The code is as follows
|
Copy code
|
||||||||
|
The code is as follows | Copy code | ||||
//Batch deletion //na is name function checkSubmit(na,url) { var str = ''; for(var i=0;i < document.getElementsByName(na).length;i++) { If(document.getElementsByName(na)[i].checked){ If(str=='') str += document.getElementsByName(na)[i].value; else str += ',' + document.getElementsByName(na)[i].value; } If(str=='') { alert('You have not selected anything!'); return false; } else { location=url+"?id="+str+"&action=delall"; } } In the php program we need to use
|