【发布时间】:2010-09-26 22:12:33
【问题描述】:
我是 jQuery 的新手。到现在为止只需学习和使用 3 周。 我写了一个类来组织东西。 我用超过 2 个事件调用我的方法,但在触发第二个事件期间该事件不起作用。 选择器没有问题。 我觉得我的课上少了点什么。我不知道。 请帮忙! 这是sn-p:
$("#btnPersonalNext, #btnDocListBack, #pDocList").livequery('click',function()
{
var docListContent = 'loadDocumentList.php';
$("#contentpaper").addContent(
{
_tag:'div',
_id: 'contentDocList',
_class: 'content',
_content: docListContent,
_heading: 'Document List'
});
//store personal info in session:
});
addContent() 是函数。
当我单击#btnPersonalNext 时,这有效,但对于#btnDocListBack,不再有效。
这是我的课 (jquery.content.js)。它的作用是将html加载到具有特定_id的特定_tag中。
(function($)
{
$.fn.addContent = function(options)
{
var defaults = {
_tag: 'div',
_id: '',
_class: '',
_content: '',
_heading: '',
_clearExisting:'yes',
_insertAfterID:'',
_deleteBeforeInsert:'no'
};
var options = $.extend(defaults, options);
return this.each(function()
{
obj = $(this);
if(options._clearExisting=='yes'){
obj.empty();
}
if(options._deleteBeforeInsert =='yes'){
$('#'+options._id).remove();
}
var innerHtml = '<' + options._tag + ' id="' + options._id + '" class="' + options._class + '">';
if(options._heading!=''){
innerHtml += '<h2>' + options._heading + '</h2>';
}
if(/^[A-Za-z0-9]+\.php(\??([A-Za-z0-9]+=[A-Za-z0-9]+)(&[A-Za-z0-9]+=[A-Za-z0-9]+)*)?$/.test(options._content))
{//if .php
$.get(options._content,function(data)
{
//handle response from server here.
innerHtml += data;
innerHtml +='</' + options._tag + '>';
if(options._insertAfterID !=''){
$('#'+options._insertAfterID).after(innerHtml);
}
else{
obj.html(innerHtml);
}
});
} // PHP rule
else
{// .html
innerHtml += options._content;
innerHtml +='</' + options._tag + '>';
if(options._insertAfterID !=''){
$('#'+options._insertAfterID).after(innerHtml);
}
else{
obj.html(innerHtml);
}
} // HTML rule
}); // End of Returned Function
};// End of addContent definition
})(jQuery);
希望得到答案,非常感谢!
这是我的 DOM 结构:
请启用 JavaScript 以继续