我可能是第一次从头开始编写一个网站,并且陷入了 javascript 的困境。 我的想法是通过单击触发链接,这将同时运行两个 JavaScript。 情况如下:
点击链接:
<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”链接/按钮上单击两次才能显示 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
});
}
});
关于javascript - 如何合并两个脚本并同时触发它们?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26879047/