我对编码相当精通,但偶尔我会遇到一些代码,它们似乎基本上做着相同的事情.我的主要问题是,为什么你会使用.append()
而不是.after()
或副诗节?
我一直在寻找,似乎找不到两者之间的区别以及何时使用和何时不使用的明确定义.
一个比另一个有什么好处?为什么我要使用一个而不是另一个??谁能给我解释一下吗?
var txt = $('#' + id + ' span:first').html();
$('#' + id + ' a.append').live('click', function (e) {
e.preventDefault();
$('#' + id + ' .innerDiv').append(txt);
});
$('#' + id + ' a.prepend').live('click', function (e) {
e.preventDefault();
$('#' + id + ' .innerDiv').prepend(txt);
});
$('#' + id + ' a.after').live('click', function (e) {
e.preventDefault();
$('#' + id + ' .innerDiv').after(txt);
});
$('#' + id + ' a.before').live('click', function (e) {
e.preventDefault();
$('#' + id + ' .innerDiv').before(txt);
});