Document. getElementById ('') is the id feature of an element to obtain a specified element. An object is returned. Document. getElementById ('') obtains the control object based on the control TAG (type attribute) and returns an array of objects;
To achieve a full-selection effect, you must define a set of options first.
The code is as follows: |
Copy code |
<Body> <P id = "btn"> <input id = "hk" type = "checkbox"/> select all </p> <Input type = "checkbox"/> <br/> <Input type = "checkbox"/> <br/> <Input type = "checkbox"/> <br/> <Input type = "checkbox"/> <br/> <Input type = "checkbox"/> <br/> <Input type = "checkbox"/> <br/> <Input type = "checkbox"/> <br/> </Body> |
Next, use Javascript to achieve the effect. The effect in the tutorial is that you can only select all selected items when you click all. If you click all selected items, you cannot select all items. Here, I have added this function through my understanding.
The code is as follows: |
Copy code |
<Script type = "text/javascript"> Window. onload = function (){ Var oInput = document. getElementsByTagName ('input ') Var ohk = document. getElementById ('HK ') Ohk. onclick = function (){ Var I = 0; If (ohk. checked = true ){ For (I = 0; I <oInput. length; I ++) { OInput [I]. checked = true; } } Else { For (I = 0; I <oInput. length; I ++) { OInput [I]. checked = false; } } }; }; </Script> |
I personally feel that this method is still lacking. He will select all the types on the page as input. Now we have written a click event to select all.
The code is as follows: |
Copy code |
<Meta charset = "utf-8"> <Script language = "javascript"> Function selectAll () { Obj = document. getElementsByName ('range '); For (var I = 0; I <obj. length; I ++) { // Document. form1.range [I]. checked = true; Obj. item (I). checked = true; } } Function unSelect () { Obj = document. getElementsByName ('range '); For (var I = 0; I <obj. length; I ++) { If (obj. item (I). checked) { Obj. item (I). checked = false; } Else { Obj. item (I). checked = true; } } } </Script> <Form name = "form1"> <Input type = "checkbox" value = "1" name = "range"> 1 <br> <! -- <Input type = "checkbox" value = "3" name = "range"> 3 <br> <Input type = "checkbox" value = "4" name = "range"> 4 <br> <Input type = "checkbox" value = "5" name = "range"> 5 <br> --> <Input type = "button" value = "select all" onclick = "selectAll ();"> <Input type = "button" value = "invert" onclick = "unSelect ();"> </Form>
|
In this way, if the deletion function is also implemented in combination with the php program, we only need to provide the obtained string in post or get mode. The following describes how to provide the get method.
The code is as follows: |
Copy code |
// Batch delete // 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 didn't select any content! '); Return false; } Else { Location = url + "? Id = "+ str +" & action = delall "; } } |
In the php program
The code is as follows: |
Copy code |
$ A = $ _ GET ['id']; |
Then, you can use where id in ($ a) to delete it. This is also a simple php Tutorial. If you need it, you can learn and communicate with others.