0
我有這樣的jQuery代碼JQuery問題。點擊 - 開放代碼
jQuery(\'.tpcoupon-reveal\').click(function() {
jQuery(\'.inner-code\').css(\'background-color\',\'#FFF\');
jQuery(\'.inner-code\').text(jQuery(this).attr(\'caption\'));
visitstore = jQuery(this).attr(\'url\');
window.open(visitstore);
});
$newText = '
<div class="tpcoupon-code-wrapper">
<span class="tpcoupon-msg"> '.tpbox2_unhtmlentities($content).'</span>
<span class="tpcoupon-reveal" caption="'.$couponcode.'" url="'.$url.'">Vis koden & besøg siden</span>
<span class="tpcoupon-code-show">
<span class="inner-code"></span>
</span>
</div>
<div class="clr"></div>
';
由於此代碼時,我跨度對象上點擊ID爲tpcoupon,揭示它我表示跨度對象ID爲內碼碼 的問題是,我在一頁中有很多塊。但是當我單擊一個跨度時,它會打開所有跨度中的所有代碼,其中id = inner-code 如何使JQuery僅打開此塊?
** ID必須是唯一的**。將你的id改爲class並在函數上下文中使用'$(this)'。 – Ohgodwhy