简体   繁体   English

我的脚本只运行一次,我希望无限次不重新加载html页面

[英]My script runs only once, I want unlimited times without reloading the html page

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Animations</title>


    <link rel="stylesheet" type="text/css" href="css/animate.css">

    <script src="js/jquery.js"></script>

    <script type="text/javascript">


      $(document).ready(function(){

            $(".box").on("click", function(){

              $(".container").addClass("animated rollIn");
             //$(".container").addClass("rollIn"); we have the same result


            });



            $("#join_us button").on("click", function(){

              $(this).addClass("animated shake");

            });


        });

    </script>
</head>

Why the two functions are executed only at the first time (only once) each of them when I click the box and button of my html page? 为什么当我单击html页面的框和按钮时,这两个函数仅在第一次(仅执行一次)时执行? Do you have any solution? 你有什么解决办法吗? I searched a lot here the topics but I didn't manage to fix the problem. 我在这里搜索了很多主题,但未能解决问题。

Ps: sorry for any mistake if any, it's the first time I post a topic. ps:很抱歉有任何错误,这是我第一次发布主题。

Try using this, where the class is added in setTimeout 尝试使用此方法,在setTimeout添加类

 <div class="container">DIV 1</div> <button class="box">Roll In</button> <div id="join_us"> <button>Shake It</button> </div> <link href="https://daneden.github.io/animate.css/animate.min.css" rel="stylesheet"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script> $(document).ready(function(){ $(".box").on("click", function(){ $(".container").removeClass("animated rollIn"); setTimeout(function(){ $(".container").addClass("animated rollIn"); },1); }); $("#join_us button").on("click", function(){ var button = $(this); button.removeClass("animated shake"); setTimeout(function(){ button.addClass("animated shake"); },1); }); }); </script> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我只希望页面刷新一次 - i want my page refresh only once 脚本只应运行一次就运行很多次 - script runs many times when it should only run once 我想在不重新加载的情况下重新开始活动。 无限或多次 - I want to restart the event without reloading. Infinite or multiple times 我需要修复 setInterval 以便它每个间隔只运行一次我的代码 - 目前运行太多次 - I need to fix setInterval so that it only runs my code once every interval - currently runs too many times 我想在不重新加载页面的情况下从数据库显示div中的数据。 我该怎么做? - I want to show my data in div from database without reloading the page. How I can do this? 如何为此JavaScript / HTML代码添加一个按钮,以便我的代码仅在按下按钮后才会运行? - How do i add a button to this JavaScript/HTML code, so that my code only runs once the button is pressed? 我的移动菜单Jquery脚本仅运行一次 - My mobile menu Jquery script only runs once 我想更改页面内容而不重新加载角度6 - I want to change the page content without reloading in angular 6 我想显示数据库结果而不重新加载页面 - I want to show result from database without reloading the page 我想获得结果而无需再次重新加载页面。 (异步) - I want to get results without reloading the page again. (Asynchronously)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM