如何合并两个脚本并同时触发它们?

时间:2014-11-12 04:02:32

标签: javascript jquery html merge

我可能是第一次从头开始写一个网站,我被困在javascript中。 我的想法是通过点击触发链接,这将同时运行两个javascripts。 情况如下:

点击链接:

<li><p class="button"><a href="video_iframe.html" target="iframe">VIDEO</a></p></li>

iframe作为目标:

<li><iframe width="800px" height="1000px" frameBorder="0" name="iframe"></iframe></li>

js 1:

<script>
$('.button').click(function () {
$(this).toggleClass('active');
if ($(this).hasClass('active')) {
    $('#zelena').stop().animate({
        left: 151
    });
} else {
    $('#zelena').stop().animate({
        left: -649
    });
}
});
</script>

js 2:

<script>
$(".button").on("click", function() {
$(this).toggleClass("underline");
$(".button").not(this).removeClass("underline");

}); 
</script>

在这里我上传了整个网站:http://www.filedropper.com/mgwebslidefinaliframe

(问题是我必须在“VIDEO”链接/按钮上点击2次才能显示iframe内容,这就是问题所在,因为在第二次点击时它应该像现在这样关闭。所以因为没有必要的第二次点击,我们无法看到iframe内容... 提前感谢您的帮助。

2 个答案:

答案 0 :(得分:1)

$('.button').on('click', function () {
    $(this).toggleClass('active underline');
    $(".button.underline").not(this).removeClass("underline");
    if($(this).hasClass('active')) {
        $('#zelena').stop().animate({
            left: 151
        });
    } else {
        $('#zelena').stop().animate({
            left: -649
        });
    }
}); 

答案 1 :(得分:0)

您已添加对该按钮的引用。只需将以下属性添加到iframe代码:src =&#34; video_iframe.html&#34;并删除添加到按钮的标签。我认为这应该可以解决你的问题。

相关问题