[英]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.