国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

按下按鈕時(shí),逐個(gè)在iframe中打開(kāi)鏈接
P粉949848849
P粉949848849 2023-09-03 15:44:43
[PHP討論組]
<p>我有一個(gè)包含三個(gè)鏈接的數(shù)組,用于在頁(yè)腳中使用的按鈕,當(dāng)我一次又一次按下該按鈕時(shí),數(shù)組將一一正常工作。。并且每次按下時(shí)都會(huì)顯示一個(gè)鏈接按鈕。那很好。 但我想,當(dāng)我點(diǎn)擊按鈕時(shí),<em>“鏈接”應(yīng)該在“iframe”中打開(kāi)</em> 。。。我使用 iframe 代碼向它們傳遞 src= 按鈕 id 但不起作用。。請(qǐng)?jiān)谙旅娴拇a和幫助。。 。 我的帶有數(shù)組的按鈕代碼</p> <pre class="brush:php;toolbar:false;">&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt; &lt;style&gt; 。footer { position: fixed; left: 0; bottom: 0; width: 100%; background-color: red; color: white; text-align: center; } &lt;/style&gt; &lt;script&gt; let link = new Array() link[0] = &quot;https://www。clc-uk。org。uk/cms/cms。jsp?menu_id=26131&amp;postcode=AL3+8QE&amp;distance=20&quot; link[1] = &quot;https://www。clc-uk。org。uk/cms/cms。jsp?menu_id=26131&amp;postcode=AL5+3NG&amp;distance=20&quot; link[2] = &quot;https://www。clc-uk。org。uk/cms/cms。jsp?menu_id=26131&amp;postcode=AL4+3NS&amp;distance=20&quot; let intlinkIndex = 0; function writeLink() { if (intlinkIndex &gt;= link。length) { let btn = document。getElementById('btn'); btn。style。display = 'none'; mylink。style。display = 'none'; } document。getElementById('mylink')。innerHTML = '&lt;a href=&quot;' + link[intlinkIndex] + '&quot;&gt;' + link[intlinkIndex] + '&lt;/a&gt;'; intlinkIndex++; } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div class=&quot;footer&quot;&gt; &lt;button id=&quot;btn&quot; onclick=&quot;writeLink();&quot;&gt;Click Me&lt;/button&gt; &lt;div id=&quot;mylink&quot;&gt;&lt;/div&gt; &lt;br&gt; &lt;iframe id=&quot;iframe&quot; src=&quot;mylink&quot; width=&quot;100%&quot; height=&quot;400&quot;&gt;&lt;/iframe&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt;</pre></p>
P粉949848849
P粉949848849

全部回復(fù)(1)
P粉579008412

在生成鏈接的HTML時(shí),可以通過(guò)在target中指定iframe的名稱來(lái)獲取它。

所以在你的iframe中添加一個(gè)name屬性,如下所示:

<iframe id="iframe" name="iframe" src="mylink" width="100%" height="400"></iframe>

然后添加一個(gè)target屬性。

document.getElementById('mylink').innerHTML = '<a href="' + link[intlinkIndex] + '" target="iframe">' + link[intlinkIndex] + '</a>';
function writeLink() {
    if (intlinkIndex >= link.length) {
      let btn = document.getElementById('btn');
      btn.style.display = 'none';
      mylink.style.display = 'none';
    }
    document.getElementById('mylink').innerHTML = '<a href="' + link[intlinkIndex] + '">' + link[intlinkIndex] + '</a>';
    document.getElementById('iframe').src = link[intlinkIndex];
    intlinkIndex++;
  }

完整源代碼

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.footer {
   position: fixed;
   left: 0;
   bottom: 0;
   width: 100%;
   background-color: red;
   color: white;
   text-align: center;
}
</style>

<script>
let link = new Array()
link[0] = "https://www.clc-uk.org.uk/cms/cms.jsp?menu_id=26131&postcode=AL3+8QE&distance=20"
link[1] = "https://www.clc-uk.org.uk/cms/cms.jsp?menu_id=26131&postcode=AL5+3NG&distance=20"
link[2] = "https://www.clc-uk.org.uk/cms/cms.jsp?menu_id=26131&postcode=AL4+3NS&distance=20"

let intlinkIndex = 0;

function writeLink() {
  if (intlinkIndex >= link.length) {
    let btn = document.getElementById('btn');
    btn.style.display = 'none';
    mylink.style.display = 'none';
  }
    document.getElementById('mylink').innerHTML = '<a href="' + link[intlinkIndex] + '">' + link[intlinkIndex] + '</a>';
    document.getElementById('iframe').src = link[intlinkIndex];
    intlinkIndex++;
}
</script>





</head>
<body>



<div class="footer"> 

<button id="btn" onclick="writeLink();">Click Me</button>

<div id="mylink"></div>

<br>


<iframe id="iframe" src="mylink" width="100%" height="400"></iframe>

</div>

</body>
</html>
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板
關(guān)于我們 免責(zé)申明 意見(jiàn)反饋 講師合作 廣告合作 最新更新
php中文網(wǎng):公益在線php培訓(xùn),幫助PHP學(xué)習(xí)者快速成長(zhǎng)!
關(guān)注服務(wù)號(hào) 技術(shù)交流群
PHP中文網(wǎng)訂閱號(hào)
每天精選資源文章推送
PHP中文網(wǎng)APP
隨時(shí)隨地碎片化學(xué)習(xí)
PHP中文網(wǎng)抖音號(hào)
發(fā)現(xiàn)有趣的

Copyright 2014-2025 http://m.miracleart.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)