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

我的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 asp.textbox后台赋值前端不能显示什么原因
  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误