因此,我在我的主頁上有多個選項卡。其中一個名爲「刷新」的按鈕只刷新該特定選項卡。這裏是我的代碼:刷新標籤內容不起作用的按鈕
外部腳本文件:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
的標籤結構:
<ul class="tabs">
<li><a href="#sm">SM</a></li>
<li><a href="#rm">RM</a></li>
</ul>
<div class="tab-content">
<div class="tab" id="rm">
//code
</div>
<div class="tab" id="sm">
<button id="refresh">REFRESH!</button>
//code
</div>
</div>
jQuery的(我已經包含在我沒有上面提到的外部文件) :
$(document).ready(function(){
$('body').on('click', '#refresh', function(){
var x = $(".tabs").tabs("option", "active");
$(".tabs").tabs("load", x);
});
});
每當我點擊按鈕,我的控制檯中會出現一個錯誤: Error: cannot call methods on tabs prior to initialization; attempted to call method 'option'
請幫忙!我對此很陌生,無法解決這個問題!
其中約你插入你的 「外部腳本文件:」?頭部或身體內? –
@Os在頭 – meagler
@Os,所以我應該刪除從頭部的鏈接,並將其轉移到身體的盡頭? – meagler