0
相關問題,這裏也有我的腳本:JQuery的多個標籤組
jQuery, multiple tab groups on one page jquery conflict with identical scripts
因此,作爲標題說我有一個包含多個選項卡組的頁面。標籤只能在第一組上工作,並停止對其餘的工作。
腳本:
$(function() {
$(".tab_content").hide();
$("ul.tabs").each(function() {
$(this).find('li:first').addClass("active");
$(this).next('.panes').find('.tab_content:first').show();
});
$("ul.tabs").each(function() {
$("ul.tabs li a").click(function() {
alert("hello");
var cTab = $(this).closest('li');
cTab.siblings('li').removeClass("active");
cTab.addClass("active");
cTab.closest('ul.tabs').nextAll('.panes:first').find('.tab_content').hide();
var activeTab = $(this).attr("href"); //Find the href attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active ID content
return false;
});
});
完整的HTML:
<table id="cform" style="margin-left: 13px;">
<tbody><tr>
<td>
<form id="form1" name="form1" method="post" action="">
<div>
<div>
<div>
<b>Subject:</b>
<select name="email_id[]" id="email_id_0" style="width: 350px">
<optgroup label="Emails">
<option value="">-- Select --</option><option value="1">test(Email)</option><option value="2">test(Email)</option><option value="3" selected="">tesst(Email)</option>
</optgroup>
<optgroup label="SMS">
</optgroup>
</select> <br>
<b>Subject:</b>
<select name="email_id[]" id="email_id_1" style="width: 350px;margin-right: 5;">
<optgroup label="Emails">
<option value="">-- Select --</option>
<option value="1">test</option><option value="2">test</option><option value="3">tesst</option> </optgroup>
<optgroup label="SMS">
</optgroup>
</select>
<center> <input type="button" class="btn-link right" value="Add More" onclick="javascript:addRows();"></center>
</div>
</div>
</div>
<br>
<div style=" margin-top: 25px; ">
<b>Scheduled (Days)</b>
<br>
<ul class="tabs">
<li class=""><a href="#tab1">Days</a></li>
<li class="active"><a href="#tab2">Weekly</a></li>
<li class=""><a href="#tab3">Monthly</a></li>
<li class=""><a href="#tab4">Yearly</a></li>
</ul>
<div class="panes">
<div id="tab1" class="tab_content" style="padding-top: 20px; display: none;">
days
</div>
<div id="tab2" class="tab_content" style="padding-top: 20px; display: block;">
weekly
</div>
<div id="tab3" class="tab_content" style="padding-top: 20px; display: none;">
monthly
</div>
<div id="tab4" class="tab_content" style="padding-top: 20px; display: none;">
yearly
</div>
</div>
<br>
<input type="hidden" name="rows_ctr" id="rows_ctr" value="1">
<input type="hidden" name="gid" id="" value="1">
<input type="submit" value="Save" class="btn-link right">
</div>
</form>
</td>
</tr><tr><td><form>
<div>
<div>
<div>
<b>Subject:</b>
<select name="email_id[]" id="email_id_1" style="width: 350px;margin-right: 5;">
<optgroup label="Emails">
<option value="">-- Select --</option>
<option value="1">test</option><option value="2">test</option><option value="3">tesst</option> </optgroup>
<optgroup label="SMS">
</optgroup>
</select>
<center> <input type="button" class="btn-link right" value="Add More" onclick="javascript:addRows();"></center>
</div>
</div>
</div>
<br>
<div style=" margin-top: 25px; ">
<b>Scheduled (Days)</b>
<br>
<ul class="tabs">
<li class="active"><a href="#tab5">Days</a></li>
<li><a href="#tab6">Weekly</a></li>
<li><a href="#tab7">Monthly</a></li>
<li><a href="#tab8">Yearly</a></li>
</ul>
<div class="panes">
<div id="tab5" class="tab_content" style="padding-top: 20px; display: block;">
days
</div>
<div id="tab6" class="tab_content" style="padding-top: 20px; display: none;">
weekly
</div>
<div id="tab7" class="tab_content" style="padding-top: 20px; display: none;">
monthly
</div>
<div id="tab8" class="tab_content" style="padding-top: 20px; display: none;">
yearly
</div>
</div>
<br>
<input type="hidden" name="rows_ctr" id="rows_ctr" value="1">
<input type="hidden" name="gid" id="" value="1">
<input type="submit" value="Save" class="btn-link right">
</div>
</form></td></tr>
</tbody></table>
注意,這是動態的,因此,我可以添加更多的組,動態部分是持有形式TR。
謝謝
試過,仍然沒有工作,你可以爲你的答案提供JS小提琴? – magicianiam 2013-05-06 21:45:15
[http://jsfiddle.net/NgZ7E/](http://jsfiddle.net/NgZ7E/) – Mamuz 2013-05-06 21:47:28
它確實對你的jsfiddle,但對我而言不會工作工作,我不知道什麼是錯在這裏。 – magicianiam 2013-05-06 21:55:03