插件下載地址:
http://xiazai.VeVB.COm/201803/yuanma/jquery.onoff(VeVB.COm).rar

一個按鈕小插件,首先引入css和js
<script type="text/javascript" src="../js/jquery-1.11.3.js" ></script> <link rel="stylesheet" href="../js/dist/jquery.onoff.css" rel="external nofollow" /> <script type="text/javascript" src="../js/dist/jquery.onoff.js" ></script>
html只需要寫一個input
<input type="checkbox" checked onclick="showmodel(this)"/>
然后js中只需要加一個.onoff()
$('input[type=checkbox]').onoff(); 你會發(fā)現(xiàn)一個普通的checkbox變成了開關(guān)按鈕
關(guān)于顏色和樣式,自己去css中找到相應(yīng)的位置修改即可
onoffswitch-inner:before { content: "OFF"; padding-left: 3px; color: #FFFFFF; background-color: #A14776; } onoffswitch-inner:after { content: "ON"; padding-right: 5px; color: #999999; background-color: #EEEEEE; text-align: right; } 關(guān)于事件

我點(diǎn)擊開關(guān)顯示模態(tài)框
jq控制開關(guān)只需要這樣就行
$(ele).prop("checked",true) //或false function showmodel(ele){ if(!$(ele).is(':checked')){ var htmls=$(ele).parent().siblings('span').html(); $('.mask').show(); $('#reportName').html(htmls); $('#yzmBox').html(mathRand()); } $(".cancel").unbind().click(function(){ $(ele).prop("checked",true) $('.mask').hide(); }) $(".sure").unbind().click(function(){ if($(".telBox input").val()==$('#yzmBox').html()){ /*$.ajax({ url: ipAddress + "/MMSDailyBackstage/task2/getTaskTypes", data:{"areaCode":"01","roleCode":"dhxt","appCode":"day_report","imei":"111111111111111"}, type : "POST", dataType: "json", cache: false, async: false, success:function(json){ var data=json.data; var html=""; if(json.success){ for(var i in data){ var taskTypeSubs=data[i].taskTypeSubs; html+='<div class="col">'+ '<p onclick="sliderDiv(this)"><span class="arrow down_a"></span><span>'+data[i].taskType.taskTypeName+'</span></p>'+ '<ul class="lidetail">' for(var j in taskTypeSubs){ html+='<li>'+ '<img src="../img/aduiticon.png">'+ '<span>'+taskTypeSubs[j].subTaskName+'</span>'+ '<input type="checkbox" checked/ onclick="showmodel(this)">'+ '</li>' } html+='</ul></div>' } $('#auditBox').append(html); $('input[type=checkbox]').onoff(); } } });*/ } }) } 總結(jié)
以上所述是小編給大家介紹的jquery.onoff實(shí)現(xiàn)簡單的開關(guān)按鈕功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對武林網(wǎng)網(wǎng)站的支持!
新聞熱點(diǎn)
疑難解答