隐藏iframe直到链接被点击,然后在链接被点击后隐藏链接

hide iframe until link is clicked then hide link after link is clicked

本文关键字:链接 隐藏 然后 iframe      更新时间:2023-09-26

我有这个代码打开链接在iframe

<a href="http://www.example.com/" target="iframe1">link</a>
</br></br>
<iframe id="iframe1" name="iframe1" src="#"></iframe>

我想隐藏iframe直到链接被点击然后隐藏链接后链接点击

我需要使用javascript/jQuery

谢谢

我会这样做:

<div id="linkDiv">
    <a href="#" id="theLink">Link</a>
</div>
<br/><br/>
<iframe id="iframe1" name="iframe1" src="#"></iframe>
$(document).ready(function(){
    $("#iframe1").hide();
    $("#theLink").click(function(){
        $("#iframe1").show();
        $("#linkDiv").hide();
        return false;
    });
});

将链接放在Span标签中,并执行以下操作:

$("#link").click(function(e) {
    e.preventDefault();
    //Assuming you're assigning the source dynamically, if not, comment out below line.
    $("#iframe1").attr("src", $("link").attr("value");
    $("#iframe1").show();
    $("#linkBeGone").hide();
});

将链接的href属性设为"#",并将该值设为iFrame的src值

<span id="linkBeGone"><a id="link" value="http://www.example.com/" href="#" target="iframe1">link</a></span>
</br></br>
<iframe id="iframe1" name="iframe1" src="#"></iframe>