我很新手jquery。我有一個導航欄,並試圖根據我選擇的內容來更改標籤。h1標記不會通過jquery .html()
$(document).ready(function() {
\t $('a').click(function(){
\t the = $(this).html();
\t linkvalue = $(this).attr('data-link');
\t $('#whatItIs').html(the);
\t console.log(the);
\t console.log(linkvalue);
\t
\t switch(the) {
\t case "Steel Products":
\t \t { \t
\t \t \t window.location.href = linkvalue;
\t \t break;
\t \t }
\t case "Steel Doors":
\t { \t
\t \t
\t \t window.location.href = linkvalue;
\t \t break;
\t \t }
\t case "Digital Safes":
\t \t {
\t \t
\t \t window.location.href = linkvalue;
\t \t break;
\t \t }
\t case "Security Equipment":
\t \t {
\t \t \t \t
\t \t window.location.href = linkvalue;
\t \t break;
\t \t } \t
\t case "Storage Solutions":
\t \t {
\t \t \t
\t \t window.location.href = linkvalue;
\t \t break;
\t \t }
\t case "Steel Furniture":
\t \t {
\t \t
\t \t window.location.href = linkvalue;
\t \t break;
\t }
\t default:
\t {
\t console.log("Not Found");
\t //window.location.href = "404.html";
\t }
\t }
\t });
});
<li class="dropdown" class="active">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Manufactured Products <b class="caret"></b></a>
<ul class="dropdown-menu">
<li>
<a data-link="securityEquipment.html">Steel Products</a>
</li>
<li>
<a data-link="securityEquipment.html">Steel Doors</a>
</li>
<li >
<a data-link="securityEquipment.html">Digital Safes</a>
</li >
<li>
<a data-link="securityEquipment.html">Security Equipment</a>
</li>
<li >
<a data-link="securityEquipment.html">Storage Solutions</a>
</li>
<li>
<a data-link ="securityEquipment.html">Steel Furniture</a>
</li>
</ul>
</li>
<h1 class="page-header" id="whatItIs">
Untitled
<!-- <small>Subheading</small>
--> </h1>
的問題是,只有一秒鐘H1更改,然後又變回我已經將其設置爲原件。 這看起來很簡單。我不知道我在做什麼錯
那是因爲你加載各個環節塔新頁你點擊。 –
爲什麼不在鏈接上使用常規的href屬性?您似乎正在複製正常的瀏覽器行爲。 – jedifans
@ jedifans我必須在此上實現更多功能。我只是沒有得到那部分。我似乎無法得到這個工作 – spetiwala