我正在使用 JQVMaps 在 WordPress 站点中呈现地图。在 WordPress 之外测试代码,一切运行良好。当我将它添加到 WordPress 时,我得到了这个控制台错误:
[错误] TypeError: 'undefined' is not a function (evalating 'jQuery('#vmap').vectorMap')
这是代码:
header.php:
if (is_page(2)){ ?>
<link href="jqvmap.css" media="screen" rel="stylesheet" type="text/css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script src="<?php bloginfo('template_url'); ?>/js/jquery.vmap.js" type="text/javascript"></script>
<script src="<?php bloginfo('template_url'); ?>/js/jquery.vmap.world.js" type="text/javascript"></script>
<script src="<?php bloginfo('template_url'); ?>/js/jquery.vmap.un_regions.js" type="text/javascript"></script>
<script src="<?php bloginfo('template_url'); ?>/js/Chart.js" type="text/javascript"></script>
<?php }?>
<?php wp_head(); ?>
页脚.php:
if (is_page(2)){ ?>
<script type="text/javascript">
// pie chart options
var pieOptions = {
segmentShowStroke : true,
animateScale : false
}
// get pie chart canvas
var pie= document.getElementById("pie").getContext("2d");
jQuery(document).ready(function() { //this is where the error is
jQuery('#vmap').vectorMap({
map: 'world_en',
backgroundColor: '#fff',
borderColor: '#bbb',
borderOpacity: 1,
borderWidth: .2,
color: '#bbb',
colors: colored_regions,
hoverOpacity: 0.8,
selectedColor: '#666666',
enableZoom: false,
showTooltip: false,
onRegionOver : function (element, code, region)
{
highlightRegionOfCountry(code);
},
onRegionOut : function (element, code, region)
{
unhighlightRegionOfCountry(code);
},
onRegionClick: function(element, code, region)
{
highlightRegionOfCountry(code);
$.ajax('/get_chart_data.php', {
data: {region: region},
dataType: 'json',
success: function(response) {
new Chart(pie).Doughnut(response.pieData, pieOptions);
}
});
}
});
});
</script>
<?php }?>
我在 content-page.php 文件中有#vmap 和#pie。我已经尝试了几个 jQuery.noConflict(); 解决方案,包括在 ready(function($) 中添加 $ 并在我的 script 标签之后添加 noConflict 函数。它仍然是 WordPress 如何加载 jQuery 的问题还是还有其他问题?您可以在此处找到该站点。谢谢。