我不是一個JavaScript人,所以我在試圖做什麼時遇到了一些困難。我們有一個html頁面,用於顯示我們產品的3個不同細節的「選項卡」:描述,細節和退貨。我可以讓選項卡正確顯示,但是當我點擊選項卡標題時,JavaScript不會更改爲選項卡。無法使用製表符在HTML和JavaScript中工作
這裏是我的html,很基本的:
<html>
<head>
<link rel="stylesheet" href="skeleton.css">
<link rel="stylesheet" href="layout.css">
<link rel="stylesheet" href="base.css">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<br><br><br>
<ul class="sans tabs">
<li>
<a class="active" href="#tabinfo" style="fonrt-weight:normal">Description</a>
</li>
<li>
<a href="#tabdetails" style="fonrt-weight:normal;color:#999">Details</a>
</li>
<li>
<a href="#returns" style="fonrt-weight:normal;color:#999">Delivery & Returns</a>
</li>
</ul>
<ul class="tabs-content">
<li class="active" id="tabinfo">
<p>A description of the product would go here. A description of the product would go here. A description of the product would go here.
A description of the product would go here. A description of the product would go here. A description of the product would go here. A description of the product would go here.</p>
</li>
<li id="tabdetails">
<ul>
<li>Detail #1</li>
<li>Detail #2</li>
<li>Detail #3</li>
<li>Detail #4</li>
<li>Detail #5</li>
<li>etc.</li>
</ul>
</li>
<li id="returns">
<p>Details about returning a product would go here.</p>
<p>Details about returning a product would go here.</p>
<p>See <a href="/somelink/">Delivery & Returns</a> for more information.</p>
</li>
</ul>
<script src="tabs.js"></script>
</body>
</html>
,當然,在tabs.js文件:
$('body').on('click', 'ul.tabs > li > a', function(e) {
//Get Location of tab's content
var contentLocation = $(this).attr('href');
//Let go if not a hashed one
if(contentLocation.charAt(0)=="#") {
e.preventDefault();
//Make Tab Active
$(this).parent().siblings().children('a').removeClass('active');
$(this).addClass('active');
//Show Tab Content & add active class
$(contentLocation).show().addClass('active').siblings().hide().removeClass('active');
}
});
再說一遍,我不知道一大堆關於js,所以我相信這是與該做的,但現在我卡住了,無法弄清楚。
你包括tabs.js whioch似乎依賴於一些jQue ry代碼,但你不包括你需要的jquery.js文件。 – 2013-04-30 11:13:05
什麼是'tabs.js'?你有鏈接嗎? – Xotic750 2013-04-30 11:32:56
不相關的但是'fonrt-weight'不存在,它應該是你的標籤鏈接上的'font-weight' - 我假設的一個錯字:) – 2013-04-30 11:34:21