簡體   English   中英

在同一頁面的不同部分打開鏈接

[英]Open link in same page different section

我的應用程序中有兩個不同的 html 文件。 像這樣的東西。

<a href="/conversations/<%= c['conversation']['id'] %>" class="list-group-item">
  <div id="nav">
   <p>This is link my second page</p>
  </div>
</a>

這是我的第二頁。

div id="nav">
  <p>This is link my second page</p>
</div>

但是在這里,當我單擊鏈接時,它會重定向到第二頁。 我想要的是當我點擊鏈接時,我想在同一頁面的不同部分打開第二個 html。 像這樣的東西。 在此處輸入圖像描述

我怎樣才能做到這一點?

iframe 是您可以用來調用其他 html 頁面到您的 web 頁面的標簽

<iframe src="http://www.google.co.in" name="targetframe" allowTransparency="true" scrolling="no" frameborder="0" >
</iframe>

html

 <div>
      <a class"links" href="https://www.yourlink.com/">link1</a>
      <a class"links" href="https://www.yourlink2.com/">link2</a>
    </div>

<div id="target_div">
  content here
</div>

jquery

$(document).ready(function() {

  $(".links").click(function(event) {
    event.preventDefault();
    var url = $(this).attr("href");
    console.log(url);
    $("#target_div").html('<iframe src="' + url + '" name="targetframe" allowTransparency="true" scrolling="no" frameborder="0" ></iframe>');
  });
});

嘗試這個

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM