如何将插件添加到 Bootstrap

How to add plugins to Bootstrap

我发现 plugin 对于 Bootstrap 测量密码强度非常酷。它看起来不错,我想使用它,但我不知道如何让它工作。根据 Github 页面,您只需 "Just invoke the plugin on the password fields you want to attach a strength meter to." 即可使用它。不幸的是,他们没有告诉您将文件放在哪里,也没有告诉您实际需要使用哪些 javascript 文件。

我一直在谷歌搜索为 Bootstrap 添加或安装插件的所有可能迭代方法,但每次都一无所获。这里有人有答案吗?

在 html 页面的头部定义 bootstrap 后,只需包含插件 css 和 javascripts。

像这样:

   <!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>

<script src="your plugin source"></script>

我想 github 页面可能会与所有这些源文件混淆。您需要做的就是从此页面获取最新的缩小文件:

https://github.com/ablanco/jquery.pwstrength.bootstrap/tree/master/dist

使用

下载、上传并加载到您的 HTML 原始 bootstrap javascript 文件之后的某处
<script type="text/javascript" src="file/location/pwstrength-bootstrap-1.2.3.min.js"></script>

完成后,添加以下 javascript 代码以在 class 或元素上调用插件:

$(document).ready(function(){
    $(':password').pwstrength();
});

要添加到以前的解决方案:还 确保在您的 html 中包含 jquery,因为 bootstrap 的 js 需要它.