我的桌子上有很多开关,所以我想分别打开(开/关)每个开关。但是在这里,当我切换某个人时,它会影响到所有我认为是由于它的原因class
。请告诉我如何在不影响其他人的情况下使用每个开关,
function load_saved_exam_data() {
var tableData = '';
jQuery.post('<?php echo site_url("administrator/active_exam_c/load_activate_exams") ?>', function (e) {
if (e === undefined || e.length === 0 || e === null) {
tableData += '<tr><th colspan="8" class="alert alert-warning text-center"> -- No Data Found -- </th></tr>';
jQuery('.activate_exam_tbl tbody').html('').append(tableData);
} else {
jQuery.each(e, function (index, qData) {
// alert(qData.act_status);
var checked;
if (qData.act_status == 1) {
checked = 'checked';
} else {
checked = '';
}
index++;
tableData += '<tr>';
tableData += '<td>' + index + '</td>';
tableData += '<td>' + qData.exam_name + '</td>';
tableData += '<td>' + qData.start_date + '</td>';
tableData += '<td>' + qData.end_date + '</td>';
tableData += '<td>' + qData.ex_session_id + '</td>';
tableData += '<td><div class="btn-group">'
+ '<div class="onoffswitch"><input type="checkbox" onclick="handleClick(this);" name="onoffswitch" class="onoffswitch-checkbox" value="' + qData.exm_id + '" id="myonoffswitch" ' + checked + ' ><label class="onoffswitch-label" for="myonoffswitch"><span class="onoffswitch-inner"></span><span class="onoffswitch-switch"></span></label></div></div></td>';
tableData += '<td><div class="btn-group"><button class="btn btn-danger delete_exam_act" value="' + qData.exm_id + '"><i class="fa fa-trash-o fa-lg"></i> Remove</button></div></td>';
tableData += '</tr>';
});
jQuery('.activate_exam_tbl tbody').html('').append(tableData);
}
}, "json");
}
function handleClick(cb) {
var activation_val = jQuery(cb).val();
var activation_checked;
if (cb.checked) {
activation_checked = '1';
} else {
activation_checked = '0';
}
var data = {
activation_val: activation_val,
activation_checked: activation_checked
};
jQuery.post('<?php echo site_url("administrator/active_exam_c/update_exam_activation") ?>', data, function (d) {
// console.log(d);
if (d.status == 1) {
swal("success!", "Successfully Updated!", "success");
} else {
swal("Only one exam can be activated..", "Please deactivate active exam and try again!", "warning");
}
}, 'json');
}
此开关正在使用css
.onoffswitch {
position: relative; width: 90px;
-webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}
.onoffswitch-checkbox {
display: none;
}
.onoffswitch-label {
display: block; overflow: hidden; cursor: pointer;
border: 2px solid #999999; border-radius: 20px;
}
.onoffswitch-inner {
display: block; width: 200%; margin-left: -100%;
-moz-transition: margin 0.3s ease-in 0s; -webkit-transition: margin 0.3s ease-in 0s;
-o-transition: margin 0.3s ease-in 0s; transition: margin 0.3s ease-in 0s;
}
.onoffswitch-inner:before, .onoffswitch-inner:after {
display: block; float: left; width: 50%; height: 30px; padding: 0; line-height: 30px;
font-size: 14px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
}
.onoffswitch-inner:before {
content: "ACTIVE";
padding-left: 10px;
background-color: #2FCCFF; color: #FFFFFF;
}
.onoffswitch-inner:after {
content: "NOT ACTIVE";
padding-right: 10px;
background-color: #EEEEEE; color: #999999;
text-align: right;
}
.onoffswitch-switch {
display: block; width: 18px; margin: 6px;
background: #FFFFFF;
border: 2px solid #999999; border-radius: 20px;
position: absolute; top: 0; bottom: 0; right: 56px;
-moz-transition: all 0.3s ease-in 0s; -webkit-transition: all 0.3s ease-in 0s;
-o-transition: all 0.3s ease-in 0s; transition: all 0.3s ease-in 0s;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
margin-left: 0;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
right: 0px;
}