我是Fuel UX的新手,并尝试使复选框工作。我有以下简单的页面:
<!DOCTYPE html>
<html lang="en" class="fuelux">
<head>
<meta charset="utf-8">
<title>Fuel UX 3</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="dist/css/fuelux.min.css" rel="stylesheet" type="text/css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="//www.fuelcdn.com/fuelux/3.11.0/js/fuelux.min.js"></script>
</head>
<body>
<div class="checkbox" id="myCheckbox">
<label class="checkbox-custom" id="myCustomCheckbox1">
<input class="sr-only" type="checkbox" value="">
<span class="checkbox-label">Custom checkbox unchecked on page load 22234</span>
</label>
</div>
<script>
//javascript initialization goes here
</script>
</body>
</html>
我需要通过Javascript初始化复选框。以下作品:
$('#myCustomCheckbox1').checkbox();
以下不起作用:
$('input[type="checkbox"]').each(function(index, item) {
$(this).checkbox();
});
或
$('input[type="checkbox"]').checkbox()
如果通过Javascript初始化复选框,任何专家都可以确认复选框必须具有ID吗?或者我以错误的方式做到了?
答案 0 :(得分:1)
请查看the documentation。复选框jQuery插件只能绑定到标签,而不是包装div
(如果存在),也不能绑定input
。
您可以尝试:
$('.checkbox > label').each(function(index, item) {
$(this).checkbox();
});