Fuel UX 3:通过 Javascript 初始化是否需要元素 ID?
Fuel UX 3: is element id required for initialization through Javascript?
我是 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?还是我做错了?
请查看the documentation。复选框 jQuery 插件只能绑定到标签,不能绑定到包装 div
(如果存在),也不能绑定到 input
.
你可以试试:
$('.checkbox > label').each(function(index, item) {
$(this).checkbox();
});
我是 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?还是我做错了?
请查看the documentation。复选框 jQuery 插件只能绑定到标签,不能绑定到包装 div
(如果存在),也不能绑定到 input
.
你可以试试:
$('.checkbox > label').each(function(index, item) {
$(this).checkbox();
});