百度空间 | 百度首页 
 
查看文章
 
jquery写插件的例子
2008-11-29 00:10

http://www.robysky.com/archives/171

<script type="text/javascript">
    jQuery.noConflict();
//
// create closure
//
(function(jQuery) {
//
// plugin definition
//
jQuery.fn.hilight = function(options) {
debug(this);
// build main options before element iteration
var opts = jQuery.extend({}, jQuery.fn.hilight.defaults, options);
// iterate and reformat each matched element
return this.each(function() {
jQuerythis = jQuery(this);
// build element specific options
var o = jQuery.meta ? jQuery.extend({}, opts, jQuerythis.data()) : opts;
// update element styles
jQuerythis.css({
backgroundColor: o.background,
color: o.foreground
});
var markup = jQuerythis.html();
// call our format function
markup = jQuery.fn.hilight.format(markup);
jQuerythis.html(markup);
});
};
//
// private function for debugging
//
function debug($obj) {
if (window.console && window.console.log)
window.console.log('hilight selection count: ' + $obj.size());
};
//
// define and expose our format function
//
jQuery.fn.hilight.format = function(txt) {
return '<strong>' + txt + '</strong>';
};
//
// plugin defaults
//
jQuery.fn.hilight.defaults = {
foreground: 'red',
background: 'yellow'
};
//
// end of closure
//
})(jQuery);


jQuery("document").ready(
function(){
jQuery('#myDiv').hilight()});


类别:网页技巧 | 添加到搜藏 | 浏览() | 评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2009 Baidu