日期:2014-05-16 浏览次数:20423 次
$("span").live("click", function(event){ });
<div class="tab-h"> <span id="tab-a" class="tab-title">TabA</span> <span id="tab-b" class="tab-title">TabB</span> </div> <div id="c-tab-a" class="tab-b"> A </div> <div id="c-tab-b" class="tab-b" style="display:none;"> B </div>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script> <script> $(document).ready(function () { $("span").live("click", function () { $('.tab-b').css('display', 'none'); $('#c-' + $(this).attr('id')).css('display', 'block'); }); });</script> </head> <body> <div class="tab-h"> <span id="tab-a" class="tab-title">TabA</span> <span id="tab-b" class="tab-title">TabB</span> </div> <div id="c-tab-a" class="tab-b"> A </div> <div id="c-tab-b" class="tab-b" style="display:none;"> B </div> </body> </html>
------解决方案--------------------
$(".tab-h span").click(function () { $('div[id^="c-tab"]').hide().end().find('#c-' +$(this).attr("id")).show(); });