As shown in the figure above, (using the table plugin in jquery) The effect I wanted was: click the checkbox (id "all") in the upper-left corner, and all the checkboxes below (id "CB") will all be selected. The jquery code I started with was this:
$ ("#all"). Toggle (function () {
$ (": CheckBox"). attr ("Checked", "true");},
function () {
$ ("Table:checkbox"). Removeattr ("checked");}
);
The effect of these codes: Click the checkbox in the upper-left corner (id "all"), and all the checkboxes below (id "CB") will all be selected, and once again click on the checkbox (id "all") in the upper-left corner, all the checkboxes below ( ID "CB") will all be canceled. However, the checkbox in the upper-left corner (id "all") never appears. Online Search, the reason is:
The default action is blocked in the toggle method
In the jquery source code, toggle called Event.preventdefault () when registering the click, which is to touch the default event that was originally bound. The problem, then, is clearly that the event that was clicked with the checkbox was brutally obliterated by jquery.
After a long time, finally let me use other methods to achieve the same effect:
The code is as follows:
$ ("#all"). Click (Function (event) {
if (($ ("#all"). attr ("checked")) = = True) {
$ ("INPUT[TYPE=CHECKBOX][NAME=CB]"). each (function () {
$ (this). attr ("Checked", "true");
});
Event.stoppropagation ();
}
As for the reason for the bubbling event in the checkbox, I don't know. When the code actually does this: click the checkbox in the upper-left corner (id "all"), and all the checkboxes below (id "CB") will all be selected, and the checkbox in the upper-left corner (id "all") appears Again, click the checkbox (id "all") in the upper-left corner, and all of the checkboxes below (id "CB") will all be canceled, and the checkbox in the upper-left corner (id "all") disappears. As for the reason in the discussion "" "" "" "" "" "" "