我正在尝试使用Tagit Jquery插件,https://github.com/aehlke/tag-it 如果有人想看http://www.imagesup.net/pt-014044890133.png
,还附上照片我使用此代码的页面是standlone页面,并由template_redirect wordpress操作调用 我的代码是
jQuery(document).ready(function($){
// Error showing here - Uncaught TypeError: undefined is not a function
$('#tags').tagit({ availableTags: ["c++", "java", "php", "javascript", "ruby", "python", "c"]});
});
我也在tag-it.source代码中遇到同样的错误,如下所示
$.widget('ui.tagit', {
// Error showing here - Uncaught TypeError: undefined is not a function
options: {
allowDuplicates : false,
caseSensitive : true,
fieldName : 'tags',
placeholderText : null, // Sets `placeholder` attr on input field.
readOnly : false, // Disables editing.
removeConfirmation: false, // Require confirmation to remove tags.
tagLimit : null, // Max number of tags allowed (null for unlimited).
// Used for autocomplete, unless you override `autocomplete.source`.
availableTags : [],
以下是向wordpress添加脚本的代码
function ds_enqueue_query_scripts(){
wp_enqueue_script('jQuery');
wp_enqueue_script( 'tagit',get_template_directory_uri() .'/js/tag-it.min.js', 'jquery' );
wp_enqueue_style( 'tagitcss', DSCSS . 'tagit.css');
}
add_action('wp_enqueue_scripts', 'ds_enqueue_query_scripts' );
在页头部分编码apears,jquery在tagit之前加载...这就是我猜的方式..
<script type='text/javascript' src='http://myhostlocal/AgamWordpress/wp-includes/js/jquery/jquery.js?ver=1.11.0'></script><script type='text/javascript' src='http://myhostlocal/AgamWordpress/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.2.1'></script><script type='text/javascript' src='http://myhostlocal/AgamWordpress/wp-content/themes/desistation/js/main.js?ver=3.9.1'></script><script type='text/javascript' src='http://myhostlocal/AgamWordpress/wp-content/themes/desistation/js/tag-it.min.js?ver=3.9.1'></script>