Use jquery to simply implement the full selection.
| The code is as follows |
Copy Code |
| <! DOCTYPE html> <script type= "Text/javascript" src= "Jquery_1.6.1.js" ></script>
<body> <script type= "Text/javascript" > function SelectAll (checkbox) { $ (' input[type=checkbox] '). Prop (' Checked ', $ (checkbox). Prop (' checked ')); } </script> <input type= "checkbox" onclick= "SelectAll" (this); "/> Select all <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> |
It's very simple.
JQ provides a new method "prop" to get these properties, which is to solve the problem, we used attr to get checked properties when we returned "checked" and "", and now we use the prop method to get the property then the uniform returns True and false.
So, when to use attr (), when to use Prop ()?
1. Add attribute name This property will take effect should use Prop ();
2. There are true,false two attributes using prop ();
3. Others use attr ();
You should pay attention to this when you upgrade jquery in your project!
The following is the use of the official recommendation attr (), prop ():
| Attribute/property |
.attr() |
.prop() |
| AccessKey |
√ |
|
| Align |
√ |
|
| Async |
√ |
√ |
| Autofocus |
√ |
√ |
| Checked |
√ |
√ |
| Class |
√ |
|
| Contenteditable |
√ |
|
| Draggable |
√ |
|
| Href |
√ |
|
| Id |
√ |
|
| Label |
√ |
|
| Location (i.e. window.location) |
√ |
√ |
| Multiple |
√ |
√ |
| ReadOnly |
√ |
√ |
| Rel |
√ |
|
| Selected |
√ |
√ |
| Src |
√ |
|
| TabIndex |
√ |
|
| Title |
√ |
|
| Type |
√ |
|
Width (if needed over .width() ) |
√ |
|