cascading Effects of a checkbox
Copy Code code as follows:
<form>
The sport you love? <br/>
<input type= "checkbox" id= "Checkedall"/> Select all/Do not select <br/>
<input type= "checkbox" name= "Items" value= "Football"/> Football
<input type= "checkbox" name= "items" value= "basketball"/> Basketball
<input type= "checkbox" name= "Items" value= "Badminton"/> Badminton
<input type= "checkbox" name= "Items" value= "Table tennis"/> Pong ball
<input type= "button" id= "send" value= "Submit"/>
$ (' #CheckedAll '). Click (function () {
$ (' [Name=items]:checkbox '). attr ("Checked", this.checked);
})
When you click the check box with id "Checkedall", the checkbox group is selected, and the check box with the id "Checkedall" is not unchecked when an option is checked in the checkbox group.
To address this problem:
Copy Code code as follows:
$ (' [Name=items]:checkbox '). Click (
function () {
var flag = true;
$ (' [Name=items]:checkbox '). each (function () {
if (!this.checked)
Flag = false;
});
$ (' #CheckedAll '). attr (' checked ', flag);
})
Or you can use the total number of check boxes equal to the number of selected check boxes
$ (' [Name=items]:checkbox '). Click (
function () {
var $tmp = $ (' [Name=items]:checkbox ');
Filter out check boxes using the Filter method and assign values directly to Checkedall
$ (' #CheckedAll '). attr (' checked ', $tmp. length = = $tmp. Filter (': Checked '). length);
})
The application of the dropdown box
Copy Code code as follows:
<div class= "Content" >
<select multiple id= "Select1" style= "width:100px;height:100px"; >
<option value= "1" > Option 1</option>
<option value= "2" > Option 2</option>
<option value= "3" > Option 3</option>
<option value= "4" > Option 4</option>
<option value= "5" > Option 5</option>
<option value= "6" > Option 6</option>
<option value= "7" > Option 7</option>
</select>
<div>
<span id= "Add" > select Add to Right </span>
<span id= "Add_all" > All add to Right </span>
</div>
</div>
<div class= "Content" >
<select multiple id= "Select2" style= "width:100px;height:100px"; >
</select>
<div>
<span id= "Add" > select Add to Left </span>
<span id= "Add_all" > All add to left </span>
</div>
<div>
Add selected options to each other
$ (' #add '). Click (function () {
var $options = $ (' #select1 option:selected ');//Get selected option
$options. Appendto (' #select2 ');//append to each other
});
Add all the options to each other
$ (' #add '). Click (function () {
var $options = $ (' #select1 option ');//Get selected option
$options. Appendto (' #select2 ');//append to each other
});
Double-click an option to add to each other
$ (' #select1 '). DblClick (function () {
var $options = $ (' option:selected ', this);//Get selected option
$options. Appendto (' #select2 ');//append to each other
})
PS: $ (' option:selected ', this), $ () has 2 parameters, one is selector, one is scope. Equivalent to $ (' #select1 option:selected ')