我有两个 div (#tweeta" 和 "#tweetb")。每个都有一个子 div,类为 ".container"。
我试图在将一些文本写入“.container”div 的函数中动态传递 div 名称。这是功能。当我特别像这样引用其中一个父 div 时,此方法有效:
jQuery(function($) {
var itema = 0;
var itemsa = $('#my-tweets li:odd').length;
function tickInterval(curr, total, ID) {
if(curr < total) {
var text = $('#my-tweets li:odd:eq('+curr+')').html();
$('#tweeta > .container').html(text);
type(curr, total, text, ID);
} else if(curr == total) {
curr = 0;
tickInterval(curr, total, ID);
}
}
tickInterval(itema, itemsa, tweeta);
});
但是,当我尝试用变量“ID”替换显式 id 时,要么该函数同时应用于 #tweeta 和 #tweetb,要么我收到一条错误消息(“抛出异常但未捕获”)...
$('#' + ID).children('.container').html(text);
$('#' + ID).find('.container').html(text);
$('#' + ID > '.container').html(text);
$('div[id='+ ID +'] > div').html(text);
我现在很困惑,关于在不将父 div id 显式写入函数的情况下选择“.container”div 的最佳方法。
如果你能帮助我,我谢谢你!
阿马尔