无法调用自定义插件
Can't call custom plugin
我在调用自定义插件时遇到问题。插件 enlargeImage 根本没有从 imageSwap jQuery 代码中调用。我是新手,仍在学习js。在这一点上,我不确定我做错了什么。任何帮助或指导:)
插件代码
(function($){
$.fn.enlargeImage = function() {
return this.each(function() {
alert("This is working!");
// preload images
$("#image_list a").(function() {
var swappedImage = new Image();
swappedImage.src = $(this).attr("href");
});
// set up event handlers for links
$("#image_list").find("a").click(function(evt) {
// swap image
var imageURL = $(this).attr("href");
$("#image").attr("src", imageURL);
//swap caption
var caption = $(this).attr("title");
$("#caption").text(caption);
// cancel the default action of the link
evt.preventDefault(); // jQuery method that's cross-browser compatible
}); // end click
// move focus to first thumbnail
$("li:first-child a:first-child").focus();
});
}
})(jQuery);
jquery 代码
$(document).ready(function() {
$('#image_list').enlargeImage();
}); // end ready
目录
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Image Swap</title>
<link rel="stylesheet" href="main.css" />
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script src="jquery.imageSwap.js"></script>
<script src="image_swap.js"></script>
</head>
<body>
<section>
<h1>Ram Tap Combined Test</h1>
<ul id="image_list">
<li><a href="images/h1.jpg" title="James Allison: 1-1">
<img src="thumbnails/t1.jpg" alt=""></a></li>
<li><a href="images/h2.jpg" title="James Allison: 1-2">
<img src="thumbnails/t2.jpg" alt=""></a></li>
<li><a href="images/h3.jpg" title="James Allison: 1-3">
<img src="thumbnails/t3.jpg" alt=""></a></li>
<li><a href="images/h4.jpg" title="James Allison: 1-4">
<img src="thumbnails/t4.jpg" alt=""></a></li>
<li><a href="images/h5.jpg" title="James Allison: 1-5">
<img src="thumbnails/t5.jpg" alt=""></a></li>
<li><a href="images/h6.jpg" title="James Allison: 1-6">
<img src="thumbnails/t6.jpg" alt=""></a></li>
</ul>
<h2 id="caption">James Allison: 1-1</h2>
<p><img src="images/h1.jpg" alt="" id="image"></p>
</section>
</body>
尝试替换此代码
$("#image_list a").(function() {
var swappedImage = new Image();
swappedImage.src = $(this).attr("href");
});
自
$("#image_list a").each(function() {
var swappedImage = new Image();
swappedImage.src = $(this).attr("href");
});
相关文章:
- 使用没有插件的javascript自定义滚动条
- jQuery-用于切换内容的自定义插件
- jQuery DataTable 插件:我想自定义 jQuery DataTable
- 如何将自定义插件添加到KeystoneJS管理UI中
- 如何确定控件/插件是否从 CRM 2011 中功能区上的自定义按钮触发
- 如何使用传单为传单实时插件设置自定义图标
- "包装器”;TinyMce自定义插件
- 带有prev和next的jquery自定义循环插件
- 如何使用jQuery扩展方法为元素或类选择器创建自定义插件
- 自定义Cordova插件,释放一个保持回调而不调用它
- jQuery验证插件-比较两个选择下拉列表的自定义方法
- 自定义jQuery插件:事件未按预期运行
- 如何向jquery插件添加自定义回调
- jQuery插件自定义事件触发器未触发
- Angular.js+require.js+jQuery插件自定义指令
- 使用WordPress插件自定义帖子类型
- JQuery日历插件:自定义视图
- 禁用keyup/keydown格式时使用$. Number () - jQuery数字插件自定义D
- 使用jquery插件自定义箭头和圆点
- 使用带有类名的参数添加JQuery验证插件自定义方法