;(function($, window, document,undefined) { var AjaxPage = function(ele, opt) { this.$element = ele, this.defaults = { 'targetData': 'target_href', 'contentElemnt': '.tabContain', 'ajaxMethod' : 'GET', 'ajaxResponedType' : 'html' }, this.options = $.extend({}, this.defaults, opt) } AjaxPage.prototype = { bindEvent : function(){ var _target_data = this.options.targetData; var _ajaxMethod = this.options.ajaxMethod; var _ajaxResponedType = this.options.ajaxResponedType; var _contentElemnt = this.options.contentElemnt; this.$element.unbind().bind("click", function(){ var target_data = $(this).attr(_target_data); $.ajax({ type: _ajaxMethod, url: target_data, dataType: _ajaxResponedType, async : false, success: function(backShowHtml){ $(_contentElemnt).html(backShowHtml); } }); return false; }); } } $.fn.ajaxPagePlugin = function(options) { var ajaxPage = new AjaxPage(this, options); return ajaxPage.bindEvent(); } })(jQuery, window, document);
使用
$(document).ready(function () {
$("#page a[class='page_num']").ajaxPagePlugin({
'targetData' : 'target_href','contentElemnt':'#site_content'
});
});