3Z image based on jquery check box (asp.net+jquery) _jquery

Source: Internet
Author: User

First up Effect chart:

Html:

Copy Code code as follows:

<asp:checkboxlist id= "CheckBoxList1" runat= "server" repeatdirection= "horizontal" Flow "repeatlayout=" 280px ">
<asp:ListItem>01</asp:ListItem>
<asp:ListItem>02</asp:ListItem>
<asp:ListItem>03</asp:ListItem>
<asp:ListItem>04</asp:ListItem>
<asp:ListItem>05</asp:ListItem>
<asp:ListItem>06</asp:ListItem>
<asp:ListItem>07</asp:ListItem>
<asp:ListItem>08</asp:ListItem>
<asp:ListItem>09</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
<asp:ListItem>11</asp:ListItem>
<asp:ListItem>12</asp:ListItem>
<asp:ListItem>13</asp:ListItem>
<asp:ListItem>14</asp:ListItem>
<asp:ListItem>15</asp:ListItem>
<asp:ListItem>16</asp:ListItem>
<asp:ListItem>17</asp:ListItem>
<asp:ListItem>18</asp:ListItem>
<asp:ListItem>19</asp:ListItem>
<asp:ListItem>20</asp:ListItem>
<asp:ListItem>21</asp:ListItem>
<asp:ListItem>22</asp:ListItem>
<asp:ListItem>23</asp:ListItem>
<asp:ListItem>24</asp:ListItem>
<asp:ListItem>25</asp:ListItem>
<asp:ListItem>26</asp:ListItem>
<asp:ListItem>27</asp:ListItem>
<asp:ListItem>28</asp:ListItem>
<asp:ListItem>29</asp:ListItem>
<asp:ListItem>30</asp:ListItem>
<asp:ListItem>31</asp:ListItem>
<asp:ListItem>32</asp:ListItem>
<asp:ListItem>33</asp:ListItem>
</asp:CheckBoxList>

Js:
Copy code code as follows:

(function ($) {
$.fn.imagecheckbox = function (options) {
var defaults = {
Checked: "Images/radio.gif",
Unchecked: "No_images/radio.gif",
CSS: "On",
Hide_radios_checkboxes:false
};
var opt = $.extend (defaults, options);
This.each (function () {
var obj = $ (this);
var type = obj.attr (' type ');
var id = obj.attr (' id ');
if (!opt.hide_radios_checkboxes) {
Obj.css (' Display ', ' none ');
}
if (obj.attr (' checked ')) {
$ ("label[for= '" + ID + "']"). attr (' class ', opt.css);
}else{
$ ("label[for= '" + ID + "']"). attr (' class ', ' out ');
}
$ ("label[for= '" + ID + "']"). Click (function () {
$ ("#" + ID). Trigger ("click");
if ($ (this). attr (' class ') = = Opt.css) {
$ (this). attr (' class ', ' out ');
}else {
$ (this). attr (' class ', opt.css);
}
});
});
}
}) (JQuery);

How to use: (Send CSS together)
Copy Code code as follows:

<script type= "Text/javascript" src= "/scripts/imagetick.js" ></script>
<script type= "Text/javascript" >
$ (function () {
$ ("input[type= ' checkbox ']"). Imagecheckbox ({//The selector can be a class as OK
Checked: "/images/red.gif",
onchecked: "/images/no_check.gif",
CSS: "On"
});
});
</script>
<style type= "Text/css" >
input{}
label{display:inline-block;width:25px;height:22px;padding-top:3px;text-align:center;font:800 12px/150% Arial; position:relative;left;-210px;}
. On{background:url (/images/red.gif) no-repeat;}
. Out{background:url (/images/no_check.gif) no-repeat;}
</style>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.