我正在动态加载用户应该选择的数据库列表(如果已经完成)。我正在使用Ratchet的切换来选择类,我正在尝试使用JavaScript函数来查找切换的切换 - 到目前为止,没有运气。我对JavaScript不是很精通,所以如果这看起来微不足道,我会道歉。我一直在尝试使用的功能,类如何显示到网页,以及处理切换的CSS
内容如下:
<script type="text/javascript">
function checkClasses() {
var classes = new Array();
classes.push("COSC120");
alert(classes[0]);
$("input:checkbox[name=type]:checked").each(function()
{
classes.push($(this).val());
});
}
</script>
将课程写入页面:
echo '<div class="toggle" id="' .$row['class_id']. '" name="type">';
echo '<div class="toggle-handle"></div>';
echo '</div>';
的CSS:
.toggle {
position: relative;
display: block;
width: 74px;
height: 30px;
background-color: #fff;
border: 2px solid #ddd;
border-radius: 20px;
-webkit-transition-duration: .5s;
-moz-transition-duration: .5s;
transition-duration: .5s;
-webkit-transition-property: background-color, border;
-moz-transition-property: background-color, border;
transition-property: background-color, border;
}
.toggle .toggle-handle {
position: absolute;
top: -1px;
left: -1px;
z-index: 2;
width: 28px;
height: 28px;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 100px;
-webkit-transition-duration: .5s;
-moz-transition-duration: .5s;
transition-duration: .5s;
-webkit-transition-property: -webkit-transform, border, width;
-moz-transition-property: -moz-transform, border, width;
transition-property: transform, border, width;
}
.toggle:before {
position: absolute;
top: 3px;
right: 11px;
font-size: 13px;
color: #999;
text-transform: uppercase;
content: "no";
}
.toggle.active {
background-color: #ff7e00;
border: 2px solid #ff7e00;
}
.toggle.active .toggle-handle {
border-color: #ff7e00;
-webkit-transform: translate3d(44px, 0, 0);
-ms-transform: translate3d(44px, 0, 0);
transform: translate3d(44px, 0, 0);
}
.toggle.active:before {
right: auto;
left: 15px;
color: #fff;
content: "yes";
}
.toggle input[type="checkbox"] {
display: none;
}
我不知道是否需要更多帮助,但如果有,请询问!提前谢谢!
答案 0 :(得分:0)
棘轮会将active
添加到元素的类列表中,因此$('.toggle.active')
会为您提供一个活动切换开关的数组