html 单选打勾效果,checkbox 实现单选效果(html)

note:在html 标签类中的checkbox实现单选效果。

在最近的开发项目中,客户要求使用小方格子实现“单选”功能,显然圆点的radio被out了,只能选择chckbox的方块样式,也在网上搜过,可能有点儿脑残,没有找到。

废话不多说直接上代码:

ps:只是一个简单的demo。

checkbox实现单选效果

$(document).ready(function () {

$('.sb').click(function () {

var typeThis = typeof ($(this).attr("checked"));

switch (typeThis) {

case "string":

if ($(this).attr("checked").toLowerCase()=="checked") {

$('.sb').each(function () {

$(this).removeAttr("checked");

});

$(this).attr("checked",true);

}

break;

case "undefined":

$('.sb').each(function () {

$(this).removeAttr("checked");

});

break;

}

});

你可能感兴趣的:(html,单选打勾效果)