定义插件的结构骨架:
书中最开始使用的结构骨架如下:
代码如下:
jQuery.fn.fluginmane=function(){
return this.each(function(){
//code...
})
}
. 代码如下:
(function($){
$.fn.fluginname=function(){
return this.each(function(){
//code...
});
}
})(jQuery);
. 代码如下:
(function($){
$.fn.txtHover=function(){
return this.each(function(){
$(this).text('text changed!');
});
}
})(jQuery);
. 代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript" src="Scripts/jquery.txtHover.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#test').txtHover();
});
</script>
</head>
<body>
<p id="test">
this is test.</p>
</body>
</html>
. 代码如下:
(function ($) {
$.fn.txtHover = function () {
return this.each(function () {
var temp = $(this).text();
$(this).hover(function () {
$(this).text('text changed!');
}, function () {
$(this).text(temp);
});
});
}
})(jQuery);
. 代码如下:
(function ($) {
$.fn.txtHover = function (options) {
var defaults = { txt: 'text changed!' };
var opt = $.extend(defaults, options);
return this.each(function () {
var self = $(this);
var temp = self.text();
self.hover(function () {
self.text(opt.txt);
}, function () {
self.text(temp);
});
});
}
})(jQuery);
如对本文有疑问, 点击进行留言回复!!
轻松解决 org.apache.taglibs.standard.tlv.JstlCoreTLV 困惑
vert实践五——Json?Protocol Buffer?FlatBuffers?
[基于tensorflow的人脸检测] 基于神经网络的人脸检测8——验证训练好的神经网络
selenium + ajax抓取英雄联盟全部英雄的详细信息及多线程保存全部皮肤图片到本地
网友评论