2016-12-26 25 views
0

即時嘗試使用顏色選擇器jquery插件。 這裏是JavaScript文件的截圖: enter image description here 這裏是我的代碼初始化:TypeError:jQuery(...)。hexColorPicker不是函數

<script type="text/javascript"> 
     jQuery(function(){ 
      jQuery("#color-picker1").hexColorPicker(); 
     }); 
    </script> 

這裏是它的HTML元素來觸發它:

<input type="text" id="color-picker1" class="form-control" /> 

,但該插件犯規秀。它產生的控制檯日誌:

TypeError: jQuery(...).hexColorPicker is not a function

腳本位置:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.0/themes/smoothness/jquery-ui.css" /> 
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.0/jquery-ui.min.js"></script> 
    <script src="<?php echo base_url()?>assets/color_picker/src/jquery-hex-colorpicker.min.js"></script> <!-- color picker plugin--> 
    <link rel="stylesheet" href="<?php echo base_url()?>assets/color_picker/css/jquery-hex-colorpicker.css" /> <!-- color picker plugin--> 
+0

插件文件包含在jQuery之後並在使用之前? – Tushar

+0

可能需要移動腳本的位置,這個錯誤是典型的,當你在調用它的函數之前加載它。 – 2016-12-26 05:55:15

+0

你是否將jquery庫包含在DOM的頭標記中? –

回答

0

確保爲作爲跟着你的腳本的位置,以確保您初始化十六進制顏色選擇器後,它被加載,也丟失; in <?php echo base_url();?>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.0/themes/smoothness/jquery-ui.css" /> 
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.0/jquery-ui.min.js"></script> 
<script src="<?php echo base_url();?>assets/color_picker/src/jquery-hex-colorpicker.min.js"></script> <!-- color picker plugin--> 
<link rel="stylesheet" href="<?php echo base_url();?>assets/color_picker/css/jquery-hex-colorpicker.css" /> <!-- color picker plugin--> 

<script type="text/javascript"> 
    jQuery(function(){ 
     jQuery("#color-picker1").hexColorPicker(); 
    }); 
</script> 
相關問題