[英]How to include a jquery plugin in your code
这可能是一个很愚蠢的问题,但是我在代码中包含一个jQuery插件时遇到了麻烦。 我指的插件是: http : //davidlynch.org/projects/maphilight/docs/
我想模仿与以下内容非常相似的内容: http : //jsfiddle.net/keith/PVpgK/
但是,当我复制代码时,我不断收到错误消息,指出“ maphilight不是函数”
如何在代码中使用jquery插件? 谢谢
$(function() {
//using the jquery map highlight plugin:
//http://davidlynch.org/js/maphilight/docs/
//initialize highlight
$('.map').maphilight({strokeColor:'808080',strokeWidth:0,fillColor:'00cd27'});
//hover effect
$('#maplink1').mouseover(function(e) {
$('#map1').mouseover();
}).mouseout(function(e) {
$('#map1').mouseout();
}).click(function(e) { e.preventDefault(); });
// initialize tabbing
$(".tabs area:eq(0)").each(function(){
$(this).addClass("current");
});
$(".tab-content").each(function(){
$(this).children(":not(:first)").hide();
});
//map clicks
$(".tabs area").click(function(){
//This block is what creates highlighting by trigger the "alwaysOn",
var data = $(this).data('maphilight') || {};
data.alwaysOn = !data.alwaysOn;
$(this).data('maphilight', data).trigger('alwaysOn.maphilight');
//there is also "neverOn" in the docs, but not sure how to get it to work
if ($(this).hasClass("current") == false)
{
var thisTarget = $(this).attr("href");
$(this).parents(".tabs").find('area.current').removeClass('current');
$(this).addClass('current');
$(this).parents(".tabs").nextAll(".tab-content").children(":visible").fadeOut(1, function() {
$(thisTarget).fadeIn("fast");
});
}
return false;
});
});
您需要在HTML标头中包含指向jquery的链接。
1)从jQuery.com下载jquery
2)链接到标题中的下载文件
像这样:
<head>
...
<script src="/path/to/jquery-1.11.3.min.js"></script>
...
</head>
作为先前的答案。 但是将它们放在body标签的底部。
<html>
<head>
</head>
<body>
<script src="../path/to/jquery-1.11.3.min.js"></script>
<script src="http://davidlynch.org/js/maphilight/jquery.maphilight.min.js"></script>
</body>
</html>
您需要将以下内容添加到html代码的标题中
<script type="text/javascript" src="http://davidlynch.org/js/maphilight/jquery.maphilight.min.js">
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.