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');
難道你沒有測試它嗎?因爲我從你的問題中理解了這一點。如果你有這個頁面叫/服務等,它應該工作,因爲它只是一個JS文件,它在wordpress中工作不同。 – mithataydogmus
是的,我已經測試過,但目前不起作用。 – Nation