我有以下兩行:兩行類似的代碼,其中一行有效,另一行不行。爲什麼不?
$target_box.children('a.ajax_trigger_title').addClass('opened_post_title');
jQuery('#'+$target_box.attr('id')+' a.ajax_trigger_title').addClass('opened_post_title');
第一行是不行的,但第二個呢。爲什麼?
下面是相關的HTML,如果你一定要知道:
<div class="box" id="30" style="position: absolute; left: 350px; top: 0px; margin-top: 10px; margin-right: 10px; margin-bottom: 10px; margin-left: 10px; ">
<h2>
<a class="ajax_trigger_title" id="open_30" href="http://keepskatinbro.com/2011/01/20/some-highlights-from-ksbs-throw-down-show-down/" rel="30">
<span>Highlights from KSB’s 「Throw Down Show Down」.</span>
</a>
</h2>
</div>
$ target_box與類 「.box的」
哦,我明白了!那麼是否有必要重寫第1行,以便它以'$ target_box.'開頭,讓代碼更易於讀取? – trusktr 2011-03-07 07:27:57
@trusktr用'find'替換'children' – Adeel 2011-03-07 07:30:44