[英]How to link HTML sections?
我是網頁設計和HTML,JS,CSS的新手。
-我創建了一個包含基本標題,導航欄,圖像滑塊和基本部分的頁面。首頁看起來像這樣的atm; http://i65.tinypic.com/98a4gh.jpg
我想將“程序”部分作為具有相同標題的空白頁面打開。因此,我復制了代碼並創建了一個新的html文件,並將其鏈接為“程序” ;
<li><a href="example.html#section1" class="sec" name="section1">Programs</a></li>
如您所知,它會在同一標簽頁中以空主體打開一個新的html文件 ( “ example.html#section1”包含一個空主體)( http://i68.tinypic.com/dorzfk.png )
問題是 ; 有沒有辦法創建該部分的直接鏈接(使用任何一種語言)? 我的意思是不應使用新的html文件或iframe。 我花了很多時間進行搜索,但我認為搜索不正確。 T_T
當然,有一種方法可以使用javascript從頭開始。 像這樣的東西;
如何使用鏈接調用JavaScript? 將是一個不錯的起點。
我確實想插入我的兩分錢,這將是為了研究像引導程序和/或基礎這樣的框架,其中已經建立了許多這些東西供您直接使用。 學會自己動手做是很重要的,但是這些框架將幫助您在開始堅持這樣的事情之前先了解大局。
編輯冗余:
來自用戶EndangeredMassa:
<html> <head> <script type="text/javascript"> // Wait for the page to load first window.onload = function() { //Get a reference to the link on the page // with an id of "mylink" var a = document.getElementById("mylink"); //Set code to run when the link is clicked // by assigning a function to "onclick" a.onclick = function() { // Your code here... //If you don't want the link to actually // redirect the browser to another page, // "google.com" in our example here, then // return false at the end of this block. // Note that this also prevents event bubbling, // which is probably what we want here, but won't // always be the case. return false; } } </script> </head> <body> <a id="mylink" href="http://www.google.com">linky</a> </body> </html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.