A nice radio button based on jquery customization Radiobutton_jquery

Source: Internet
Author: User
Continue to share the Web front-end custom control, today to share the control is a radio button, I hope you have a harvest, have good suggestions also want to leave a message to me. The code is as follows:

The HTML code is as follows:
Copy Code code as follows:

<div style= "Margin:50px;float:left;" >
<b class= "Radio" _txt= "Single Choice Me" ></b>
<b class= "Radio" _txt= "Select You" ></b>
<b class= "Radio" _txt= "The single elect him" ></b>
</div>

The CSS code is as follows:
Copy Code code as follows:

. Radio{float:left;background:url (/img/icon_bg.png);
. radio{width:14px;height:14px;background-position:0px-58px;cursor:pointer;font-size:9px;}
. radio.checked{background-position: -15px-58px;
. radio_txt{float:left;margin:0px 0 0 10px;cursor:pointer;line-height:14px;font-size:12px;}
. radio_txt. radio{margin-right:5px;

JS part of the code:

1. Custom radio Button class
Copy Code code as follows:

Single option
var RadioButton = function () {
This.obj;
var _this = this, _obj;
Class
This.init = function () {
_obj = _this.obj;
var tem = _obj.length > 1? _obj.eq (0): _obj;
if (tem.attr (' class '). IndexOf (' radio ') = = 1) {
ShowMessage ("Control property settings are incorrect: Some controls are not single options!") ");
Return
}
Radio Events
var click_fun = function (obj) {
if (Obj.parent (). attr (' class ') = = ' Radio_txt ') {
Obj.parent (). Parent (). Find ('. Radio_txt. Radio '). Removeclass (' checked ');
} else
Obj.siblings ('. Radio '). Removeclass (' checked ');
Obj.addclass (' checked ');
_this.click_callback ();
};

Set a text list option
if (_obj.attr (' _txt ')!= undefined) {
_obj.each (function (i) {
var radio = _obj.eq (i);
Radio.wrapall (' <font class= ' Radio_txt "></font>");
Text Click event
Radio.parent (). Append (radio.attr (' _txt ')). Click (function () {click_fun (radio);});
});
else//Object Click event
_obj.unbind (' click '). Click (function () {Click_fun ($ (this));};
}
Click Callback Event
This.click_callback = function () {}
}

2. Instantiation:
Copy Code code as follows:

Initialize a radio box
var radio = new RadioButton ();
Radio.obj = $ ('. Radio ');
Radio.init ();

Sample Picture:

Style Collection diagram:

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.