繁体   English   中英

将html链接加载到div中

[英]load html link into div

我在div中有链接列表...当我单击链接时,我想在同一页面的另一个div中加载链接内容,这是我的代码:

<div>
 <div>
    <div style="padding-bottom:20px;">
       <center><img src="real.gif"></center>
    </div>
    <div>
       <div>
            <div style="padding-bottom:20px;">
                <a href="history.html"><h3>History of Club</h3></a>
            </div>
            <div style="padding-bottom:20px;">
                <a href=""><h3>Photos Gallery</h3></a>
            </div>
            <div style="padding-bottom:20px;">
                <a href=""><h3>Hall of Fame</h3></a>
            </div>
            <div style="padding-bottom:20px;">
                <a href=""><h3>History of Club</h3></a>
            </div>
      </div>
  </div>
</div>
<div id="linkcontent"></div>

我可以通过一个非常简单的js函数来做到这一点吗? 有什么建议么?

使用Ajax ,我建议使用jQuery ajax来更新div。

就像是:

     $("#mylink").click (function () {
        $.ajax({
           type: "POST", // or GET
           url: "mylink.php",//what ever link you want to load
           data: "someData=someThing&someMore=somethingElse",
           success: function(data){
                  $("#someElement").doSomething().
          }
     });
     return false; 
    });

将 HTML 装入<div></div><div id="text_translate"><p><em><strong>小提琴</strong>: <a href="https://jsfiddle.net/x9ghz1ko/" rel="nofollow noreferrer">https://jsfiddle.net/x9ghz1ko/</a> (带评论。)</em></p><p> 我有一个<strong>HTML 文档</strong>,在这个文档里面,有<strong>两个部分</strong>: &lt;section class="desktop_only"&gt;和&lt;section class="mobile_only"&gt; - 在代码中,在这些部分之前,有一个<strong>脚本</strong>,这个脚本应该<strong>删除两个部分之一</strong>,但问题是:为此,我必须将脚本放在部分之后,但我不能这样做,因为部分内有更多脚本,我必须删除它们在他们跑之前。</p><p> 我的代码的简化版本:(……不工作。) </p><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-html lang-html prettyprint-override"> &lt;script&gt; device = "desktop"; // This could be either: "desktop", or: "mobile" if(device === "desktop"){ document.querySelector(".mobile_only").remove(); // Not doing anything. } else { document.querySelector(".desktop_only").remove(); // Not doing anything. } &lt;/script&gt; &lt;section class="desktop_only"&gt; &lt;script src="example.js"&gt;&lt;/script&gt; &lt;script&gt; console.log("desktop_only") &lt;/script&gt; &lt;div&gt; desktop &lt;/div&gt; &lt;/section&gt; &lt;section class="mobile_only"&gt; &lt;script src="example.js"&gt;&lt;/script&gt; &lt;script&gt; console.log("mobile_only") &lt;/script&gt; &lt;div&gt; mobile (Delete this.) &lt;/div&gt; &lt;/section&gt;</pre></div></div><p></p><p> <strong>也许一种解决方案是:</strong>我有一个空的&lt;div&gt; ,称为".platform_dependent" ,我有两个外部文件,称为: desktop_only.something和mobile_only.something然后我将这些文件的内容加载到: platform_dependent.innerHTML ...但我不知道该怎么做?</p></div>

[英]load HTML into <div>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Ajax.load 向我发送链接,而不是将 html 加载到 div 中 Html div 类链接 单击该div中的链接时,无需刷新即可在div中加载html页面 如何通过单击同一链接从两个不同的div(来自html)加载两个div 在div中加载html,然后将其删除 加载html或div,菜单 将 HTML 装入<div></div><div id="text_translate"><p><em><strong>小提琴</strong>: <a href="https://jsfiddle.net/x9ghz1ko/" rel="nofollow noreferrer">https://jsfiddle.net/x9ghz1ko/</a> (带评论。)</em></p><p> 我有一个<strong>HTML 文档</strong>,在这个文档里面,有<strong>两个部分</strong>: &lt;section class="desktop_only"&gt;和&lt;section class="mobile_only"&gt; - 在代码中,在这些部分之前,有一个<strong>脚本</strong>,这个脚本应该<strong>删除两个部分之一</strong>,但问题是:为此,我必须将脚本放在部分之后,但我不能这样做,因为部分内有更多脚本,我必须删除它们在他们跑之前。</p><p> 我的代码的简化版本:(……不工作。) </p><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-html lang-html prettyprint-override"> &lt;script&gt; device = "desktop"; // This could be either: "desktop", or: "mobile" if(device === "desktop"){ document.querySelector(".mobile_only").remove(); // Not doing anything. } else { document.querySelector(".desktop_only").remove(); // Not doing anything. } &lt;/script&gt; &lt;section class="desktop_only"&gt; &lt;script src="example.js"&gt;&lt;/script&gt; &lt;script&gt; console.log("desktop_only") &lt;/script&gt; &lt;div&gt; desktop &lt;/div&gt; &lt;/section&gt; &lt;section class="mobile_only"&gt; &lt;script src="example.js"&gt;&lt;/script&gt; &lt;script&gt; console.log("mobile_only") &lt;/script&gt; &lt;div&gt; mobile (Delete this.) &lt;/div&gt; &lt;/section&gt;</pre></div></div><p></p><p> <strong>也许一种解决方案是:</strong>我有一个空的&lt;div&gt; ,称为".platform_dependent" ,我有两个外部文件,称为: desktop_only.something和mobile_only.something然后我将这些文件的内容加载到: platform_dependent.innerHTML ...但我不知道该怎么做?</p></div> 定位链接以在DIV中加载 将网页链接加载到 div 或 iframe 在div内加载RSS链接
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM