javascript 选择的 jQuery 插件不起作用。
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18568782/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Chosen jQuery plugin not functional.
提问by Sangram Singh
Using Chosen version 1.0.0 I included the following files
使用 Chosen 版本 1.0.0 我包含了以下文件
link(href='css/chosen.css', rel="stylesheet", type="text/css");
script(src='js/chosen.jquery.min.js')
script.
$(".chosen-select").chosen()
body
select(data-placeholder="Choose a country...", multiple style="width:350px;" ).chosen-select
<option value=""></option>
<option value="United States">United States</option>
<option value="United Kingdom">United Kingdom</option>
<option value="Afghanistan">Afghanistan</option>
<option value="Aland Islands">Aland Islands</option>
<option value="Albania">Albania</option>
<option value="Algeria">Algeria</option>
<option value="American Samoa">American Samoa</option>
The above code gives a disfunctional select box
The above display is same as
上面的代码给出了一个disfunctionalselect box
上面的显示是一样的
select(multiple, style="width:350px;")
<option value=""></option>
<option value="United States">United States</option>
Upon analysis I see, that both chosen.css
and chosen.jquery.min.js
have no class chosen-select
I am using jQuery version v1.10.2
Also I am loading jQuery as the first file on the page to avoid conflict.
在分析我看,这两个chosen.css
并chosen.jquery.min.js
没有阶级chosen-select
,我使用jQuery版本,v1.10.2
我也是加载的jQuery为页面上的第一个文件,以避免冲突。
Thanks for helping.
谢谢你的帮助。
回答by Sangram Singh
Adding
添加
script.
$(document).ready(function(){
$(".chosen-select").chosen()
});
Instead of just $(".chosen-select").chosen()
makes it work!
而不是$(".chosen-select").chosen()
让它工作!
回答by Fawad
Mine doesn't worked instead it worked by
我的不起作用,而是通过
<script type="text/javascript" src="js/chosen.jquery.js" >
</script>
<script>
`Enter only enter chosen related code here`
</script>
回答by Sam N
This can sometimes happened because the confliction of the jquery library. Define your JavaScript inside no conflict. https://api.jquery.com/jquery.noconflict/
这有时会发生,因为 jquery 库的冲突。定义你的 JavaScript 里面没有冲突。 https://api.jquery.com/jquery.noconflict/