我正在尝试使用 Bootstrap 开关,但遇到了一些问题。我在这里使用这个例子 http://www.jque.re/plugins/version3/bootstrap.switch/无论我使用什么类,按钮都保持相同的样式和非常小的尺寸,我什至看不到 ON 和 OFF 文本。我真的不知道我做错了什么。有什么帮助吗?谢谢
这是我的html:
<!DOCTYPE html>
<html lang="pt">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Bootstrap 101 Template</title>
<!-- Bootstrap -->
<link rel="stylesheet" href="css/jquery-ui-1.10.1.custom.css" />
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/bootstrap-switch.css" rel="stylesheet">
<link href="css/_custom.css" rel="stylesheet">
<script src="js/jquery-1.9.1.js" type="text/javascript"></script>
<script src="js/jquery-ui.js" type="text/javascript"></script>
<script src="js/bootstrap-switch.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="row">
<div class="col-lg-12">
<div class="make-switch switch-large">
<input type="checkbox" name="my-checkbox" checked>
<div class="make-switch" data-on="primary" data-off="info">
<input type="checkbox" checked name="my-checkbox">
<div id="label-switch" class="make-switch" data-on-label="SIM" data-off-label="NÃO">
<input type="checkbox" checked name="my-checkbox">
</div>
</div>
</div>
</div></div>
</form>
</div>
<script type="text/javascript">
$("[name='my-checkbox']").bootstrapSwitch();
</script>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>
最佳答案
您的依赖项出现故障;他们应该是这样的。
标题
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-switch/3.3.2/css/bootstrap3/bootstrap-switch.min.css" rel="stylesheet" />
<link href="path/custom.css" rel="stylesheet" type="text/css"/>
body 的尽头
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-switch/3.3.2/js/bootstrap-switch.min.js"></script>
<script>$("[name='my-checkbox']").bootstrapSwitch();</script>
CSS 订单
JS 订购
您还在页面上加载了 jQuery 两次,(一次在您的头部,一次在正文的末尾)在所有 JS 依赖项之前使用一次。
$("[name='my-checkbox']").bootstrapSwitch();
还需要放在所有其他 JS 依赖项之后才能加载。**旁注:您缺少一个开口
form
标记为好。$("[name='my-checkbox']").bootstrapSwitch();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-switch/3.3.2/css/bootstrap3/bootstrap-switch.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-switch/3.3.2/js/bootstrap-switch.min.js"></script>
<hr>
<form>
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="make-switch switch-large">
<input type="checkbox" name="my-checkbox" checked>
<div class="make-switch" data-on="primary" data-off="info">
<input type="checkbox" checked name="my-checkbox">
<div id="label-switch" class="make-switch" data-on-label="SIM" data-off-label="NÃO">
<input type="checkbox" checked name="my-checkbox">
</div>
</div>
</div>
</div>
</div>
</div>
</form>
关于twitter-bootstrap - Bootstrap 开关的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32680559/