Optimizing jquery checkbox script -
I am trying to be better at using Jquery and therefore would like to respond to ways to optimize my script.
To summarize the functionality, I have a button to perform the "CheckOl" checkbox and the action on the checked elements. If there is no element, then my button should be disabled and the classroom should also be disabled. If there is only one element checked then the button should not be deactivated, neither the class has been disabled.
Thank you in advance
$ (document) .ready (function () {$ ('# checkall') click (function () {$ (this). Parents ('. Table_form: eq (0)'). (': Checkbox'). ET ('check', checked this); ($ (This) .parents ('. Table_form: eq (0) (': Checkbox'). (': Check') {$ ("# delete_selected"). Attr ("disabled AddClass (" disabled ");}}) $ $ (" # delete_selected "). ("# Delete_selected"). Remover ("disabled");} and {$ ("# delete_selected"). #blog_posts tbody: checkbox "). Click (checked_status);}); Function check_status () {var n = $ ("input: checked"). Length; If (n> gt; 0) {$ ("# delete_selected") Attr ("disabled"); $ ("# Delete_selected") removeClass ("disabled"). } And {$ ("# delete_selected"). RemoveAttr ("disabled"). AddClass ("disabled"); }}
I do not have much to adapt about here, but maybe you Trying to set it to disable:
$ ("# delete_selected"). Attr ("disabled"); // will not work, returns a right or wrong return
It should be instead:
$ ("# delete_selected"). Ether ("disabled", true); // or "disabled"
and you can use chaining:
$ ("# delete_selected"). Attr ("disabled", true) removeClass ("disabled");
See
Also, this condition:
if ($ (this). Parents ('. Table_form: eq ( 0) '' (': checkbox'). (': Check')) { can be changed to a bit more brief:
If ($ (this) .closest ('. Table_form'). (': Checkbox: check'). Length) {
but this is really a preference.
Comments
Post a Comment