How do I apply Chosen jQuery in my html page?
如何在我的html页面中应用选择的jQuery?
I have a select
form so I need to use the multiple select
by Chosen to make it look more user friendly.
我有一个选择表单,所以我需要使用选择的多重选择使其看起来更加用户友好。
<select class="chosen" multiple="true" name="faculty">
<option value="AC">A</option>
<option value="AD">B</option>
<option value="AM">C</option>
<option value="AP">D</option>
</select>
I've downloaded the files and copied it into my webpage folder.
我已下载文件并将其复制到我的网页文件夹中。
So, what I did was include the chosen.jquery.min.js
in <head>
:
所以,我所做的是在中包含selected.jquery.min.js:
<script type="text/javascript" src="chosen/chosen.jquery.min.js"></script>
And the instruction says to Call the chosen plugin: $(".chzn-select").chosen();
并且指令说要调用所选的插件:$(“。chzn-select”)。selected();
I don't know where to put that JavaScript statement in order to invoke Chosen multiple select. I thought it was as easy as using Bootstrap, hah. Any help?
我不知道在哪里放置JavaScript语句以调用Chosen multiple select。我觉得它就像使用Bootstrap一样简单,哈。有帮助吗?
3 个解决方案
#1
6
If you follow one of Bootstrap's example markup structures, you'll notice that they call all their JavaScript files at the bottom (right above the </body>
tag).
如果您按照Bootstrap的示例标记结构之一进行操作,您会注意到它们在底部( 标记的正上方)调用了所有JavaScript文件。
You'll want to do the same; something like:
你也想做同样的事;就像是:
</div> <!-- /container -->
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="../assets/js/jquery.js"></script>
<script src="../assets/js/bootstrap-transition.js"></script>
<script src="../assets/js/bootstrap-alert.js"></script>
<script src="../assets/js/script.js"></script> <!-- Your custom JS -->
</body>
</html>
Inside this script.js
file, you'll want to add something like:
在这个script.js文件中,你需要添加如下内容:
$(function(){
$(".chzn-select").chosen();
});
#2
18
Your select
must have the class chzn-select
, and normally you would run a script after page load like the following:
你的select必须有chzn-select类,通常你会在页面加载后运行一个脚本,如下所示:
$(function() {
$(".chzn-select").chosen();
});
Below is a tested, working example:
下面是一个经过测试的工作示例:
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.4.2/chosen.jquery.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.4.2/chosen.css">
</head>
<body>
<script type="text/javascript">
$(function() {
$(".chzn-select").chosen();
});
</script>
<select class="chzn-select" multiple="true" name="faculty" style="width:200px;">
<option value="AC">A</option>
<option value="AD">B</option>
<option value="AM">C</option>
<option value="AP">D</option>
</select>
</body>
</html>
#3
2
<script type="text/javascript" src="chosen/chosen.jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$(".chzn-select").chosen();
});
</script>
<select class="chzn-select" multiple="true" name="faculty">
<option value="AC">A</option>
<option value="AD">B</option>
<option value="AM">C</option>
<option value="AP">D</option>
</select>
#1
6
If you follow one of Bootstrap's example markup structures, you'll notice that they call all their JavaScript files at the bottom (right above the </body>
tag).
如果您按照Bootstrap的示例标记结构之一进行操作,您会注意到它们在底部( 标记的正上方)调用了所有JavaScript文件。
You'll want to do the same; something like:
你也想做同样的事;就像是:
</div> <!-- /container -->
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="../assets/js/jquery.js"></script>
<script src="../assets/js/bootstrap-transition.js"></script>
<script src="../assets/js/bootstrap-alert.js"></script>
<script src="../assets/js/script.js"></script> <!-- Your custom JS -->
</body>
</html>
Inside this script.js
file, you'll want to add something like:
在这个script.js文件中,你需要添加如下内容:
$(function(){
$(".chzn-select").chosen();
});
#2
18
Your select
must have the class chzn-select
, and normally you would run a script after page load like the following:
你的select必须有chzn-select类,通常你会在页面加载后运行一个脚本,如下所示:
$(function() {
$(".chzn-select").chosen();
});
Below is a tested, working example:
下面是一个经过测试的工作示例:
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.4.2/chosen.jquery.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.4.2/chosen.css">
</head>
<body>
<script type="text/javascript">
$(function() {
$(".chzn-select").chosen();
});
</script>
<select class="chzn-select" multiple="true" name="faculty" style="width:200px;">
<option value="AC">A</option>
<option value="AD">B</option>
<option value="AM">C</option>
<option value="AP">D</option>
</select>
</body>
</html>
#3
2
<script type="text/javascript" src="chosen/chosen.jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$(".chzn-select").chosen();
});
</script>
<select class="chzn-select" multiple="true" name="faculty">
<option value="AC">A</option>
<option value="AD">B</option>
<option value="AM">C</option>
<option value="AP">D</option>
</select>