2012-07-12 66 views
0

我有两个div(#tweeta“和‘#tweetb’)。每一个都有带班孩子格” .container”儿童jQuery的动态选择 - 心乱如麻

我正在努力。 。在写入一些文本到“.container”分区功能动态传递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,或者该函数应用于BOTH #tweeta AND #tweetb或者我收到一条错误消息('Exception thrown and not caught')...

$('#' + ID).children('.container').html(text);

$('#' + ID).find('.container').html(text);

$('#' + ID > '.container').html(text);

$('div[id='+ ID +'] > div').html(text);

我现在很困惑,要选择 '.container' DIV没有明确地写在父DIV ID的最佳方式进入功能。

如果你能帮助我,我谢谢你!

阿迈勒

回答

0

你忘了在你的函数的第三个参数报价,它应该是:

tickInterval(itema, itemsa, 'tweeta'); 
+0

谢谢谢谢谢谢。你知道有一个工具可以接受这样的错误吗? – user1292923 2012-07-12 18:53:17

+0

[JSLint](http://www.jslint.com/lint.html)会报告未定义的变量。 – Tomek 2012-07-12 19:30:18