dongxing7530 2016-07-08 14:27
浏览 421
已采纳

我的JQuery Chosen插件不起作用

I tried to add JQuery Chosen plugin to my website, but i can't make it work on a <select> , there are 2 classes in it that are from bootstrap, i tried to chosen-select on it, didn't work.

Heres the code, also, this page is being built in PHP.

PHP-Dropbox

<select class="form-control  bfh-countries chosen-select"  data-country="PT">
     <option value="PT">Portugal</option>
     <option value="AF">Afghanistan</option>
     <option value="AL">Albania</option>
     <option value="DZ">Algeria</option>
     <option value="AS">American Samoa</option>
     <option value="AD">
     (...)

and so on.

I added the plugin at the end of the file

Import JS libray and plugin

 <script src="<?php echo site_url('https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js');?>" type="text/javascript"></script>
    <script src="<?php echo site_url('recursos/chosen/chosen.jquery.js'); ?>" type="text/javascript" >  </script>
    <link rel="stylesheet" href="<?php echo base_url();?>recursos/chosen/chosen.css" />
     <script type="text/javascript">
            $(window).load(function(){
            $(".chosen-select").chosen()
            });
        </script>

Why I can't load the plugin to the selector?

  • 写回答

1条回答 默认 最新

  • duanchun1881 2016-07-08 14:33
    关注

    You are adding your site's url infront of the google api's url , which is wrong and the jquery is not working for you at all. What site_url or base_url from codeigniter (which is your framework) does is , generate an url which is specified inside config.php file. if you put a path of any file inside these functions , it will become sort of :

    yoursite.com/your/another/path/file.js

    Change your code from this :

     <script src="<?php echo site_url('https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js');?>" type="text/javascript"></script>
        <script src="<?php echo site_url('recursos/chosen/chosen.jquery.js'); ?>" type="text/javascript" >  </script>
        <link rel="stylesheet" href="<?php echo base_url();?>recursos/chosen/chosen.css" />
         <script type="text/javascript">
                $(window).load(function(){
                $(".chosen-select").chosen()
                });
            </script>
    

    to this Updated:

     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
     <script src="<?php echo site_url('recursos/chosen/chosen.jquery.js'); ?>" type="text/javascript" >  </script>
         <script type="text/javascript">
                $(document).ready(function(){
                 $(".chosen-select").chosen();
                });
            </script>
    

    and add this line to your <head> tag not in footer :

    <link rel="stylesheet" href="<?php echo base_url();?>recursos/chosen/chosen.css" />
    

    By looking at the comment you have posted. Your path to the chosen plugin files are wrong. Please make sure you are targeting the right path.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条