Chosen jQuery plugin not functional.

ε祈祈猫儿з 提交于 2019-12-13 05:27:16

问题


Using Chosen version 1.0.0 I included the following files

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

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.

Thanks for helping.


回答1:


Adding

script.
        $(document).ready(function(){
            $(".chosen-select").chosen()
        });

Instead of just $(".chosen-select").chosen() makes it work!




回答2:


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>



回答3:


This can sometimes happened because the confliction of the jquery library. Define your JavaScript inside no conflict. https://api.jquery.com/jquery.noconflict/



来源:https://stackoverflow.com/questions/18568782/chosen-jquery-plugin-not-functional

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!