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

How to merge two scripts and trigger them both at once?

本文关键字:两个 何合并 合并 脚本      更新时间:2023-09-26

我可能是第一次从头开始写网站,我被javascript卡住了。我的想法是通过点击来触发链接,这将同时运行两个java脚本。情况如下:

点击链接:

<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>

js2:

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

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

(问题是,我必须在"视频"链接/按钮上点击两次才能显示iframe内容,这就是问题所在,因为第二次点击时,它应该像现在一样关闭。所以我们看不到iframe的内容,因为不需要第二次单击…)。。。提前感谢您的帮助。

$('.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
        });
    }
}); 

您已经添加了对按钮的引用。只需在iframe标记中添加以下属性:src="video_iframe.html",然后删除添加到按钮的a标记。我认为这应该能解决你的问题。