2016-10-24 84 views
0

我有一个脚本文件(service-graph.js),我想使它在wordpress中工作,我有JavaScript的基本knowlogdge非常基本,所以我不知道脚本是否会在wordpress中工作,内容是以下:如何在Wordpress中调用此脚本?

jQuery(document).ready(function() { 
var url = window.location.pathname; 
var path = url.split('/'); 

jQuery('.curve-item.' + path[2]).addClass('default'); 

if (path[2] == 'blueprint') 
    jQuery('.overview-graph .middle-item').addClass('default'); 

jQuery('.curve-item .logo').hover(
    function() { 
     if (jQuery(this).parent().hasClass('default')) return; 
     jQuery(this).parent().addClass('on'); 
    }, function() { 
     jQuery(this).parent().removeClass('on'); 
    } 
).css('cursor', 'pointer').on('click', function() { 
    location.href = '/services/' + jQuery(this).parent('.curve-item').data('target'); 
}); 

jQuery('.overview-graph .middle-item').on('click', function() { 
    location.href = '/services/blueprint'; 
}).css('cursor', 'pointer'); 

});

而且我用这个函数来调用上的functions.php

function wpb_adding_scripts() { 
    wp_register_script('service-graph', get_template_directory_uri() . '/js/service-graph.js', array('jquery'), '1.1', true); 
    wp_enqueue_script('service-graph'); 
} 
add_action('wp_enqueue_scripts', 'wpb_adding_scripts'); 
+0

难道你没有测试它吗?因为我从你的问题中理解了这一点。如果你有这个页面叫/服务等,它应该工作,因为它只是一个JS文件,它在wordpress中工作不同。 – mithataydogmus

+0

是的,我已经测试过,但目前不起作用。 – Nation

回答

0

脚本,这个脚本不应需在WordPress还呼吁。你有没有检查你的浏览器资源,以确保service-graph.js和jQuery被加载?我有一种感觉,这是一个jQuery版本不匹配。