1. 程式人生 > >jquery實現tab頁切換

jquery實現tab頁切換

  • 關聯設定

       <h2 class="h2_ch"><span id="tabs" class="l">
        <a href="javascript:void(0);" ref="#tab_1" title="基本資訊" class="here">基本資訊</a>
        <a href="javascript:void(0);" ref="#tab_2" title="商品描述" class="nor">商品描述</a>
        <a href="javascript:void(0);" ref="#tab_3" title="商品引數" class="nor">商品引數</a>
        <a href="javascript:void(0);" ref="#tab_4" title="商品規格" class="nor">商品規格</a>

        </span></h2>

  • 2.關聯tab

    <div id="tab_1" class="edit set" >
<p><label><samp>*</samp>第一個:</label>

    </div>

<div id="tab_2" class="edit" style="display: none">
<p><label><samp>*</samp>第二個:使用了外掛fckeditor</label>
<textarea name="itemDesc" id="itemDesc" ></textarea>
</div>
<div id="tab_3" class="edit set"style="display: none">
<p><label><samp>*</samp>第三個:</label>

</div>

<div id="tab_4" style="display: none">
<p><label><samp>*</samp>其他</label>
</div>
  • 實現jQuery程式碼

$(function(){
var tObj;
$("#tabs a").each(function(){
if($(this).attr("class").indexOf("here") == 0){tObj = $(this)}
$(this).click(function(){
var c = $(this).attr("class");
if(c.indexOf("here") == 0){return;}
var ref = $(this).attr("ref");
var ref_t = tObj.attr("ref");
tObj.attr("class","nor");
$(this).attr("class","here");
$(ref_t).hide();
$(ref).show();
tObj = $(this);
if(ref == '#tab_2'){
var fck = new FCKeditor("itemDesc");
fck.BasePath ="plugins/fckeditor/";
//圖片回顯
//fck.Config["ImageUploadURL"] = path+"/upload/uploadForFck.do";
fck.Height = 400;
fck.ReplaceTextarea();
}
});
});
})