কম্পিউটার

কিভাবে জাভাস্ক্রিপ্ট দিয়ে একটি ফাংশন কার্যকর করা বন্ধ করবেন?


জাভাস্ক্রিপ্টে একটি ফাংশন কার্যকর করা বন্ধ করতে, clearTimeout() পদ্ধতি ব্যবহার করুন। এই ফাংশন কল setTimeout() ফাংশন দ্বারা সেট করা যেকোনো টাইমার সাফ করে।

উদাহরণ

JavaScript-এ clearTimeout() পদ্ধতিতে কীভাবে কাজ করবেন তা শিখতে আপনি নিম্নলিখিত কোডটি চালানোর চেষ্টা করতে পারেন।

<html>
   <head>
      <title>JavaScript clearTimeout() method</title>
      <script>
         <!--
            var imgObj = null;
            var animate ;
           
            function init(){
               imgObj = document.getElementById('myImage');
               imgObj.style.position= 'relative';
               imgObj.style.left = '0px';
            }
            function moveRight(){
               imgObj.style.left = parseInt(imgObj.style.left) + 10 + 'px';
               animate = setTimeout(moveRight,20);    // call moveRight in 20msec
            }
            function stop(){
               clearTimeout(animate);
               imgObj.style.left = '0px';
            }
            window.onload = init;
         //-->
      </script>
   </head>
   <body>
      <form>
         <img id = "myImage" src = "/images/html.gif" />
         <p>Click the buttons below to handle animation</p>
         <input type = "button" value = "Start" onclick = "moveRight();" />
         <input type = "button" value = "Stop" onclick = "stop();" />
      </form>
   </body>
</html>

  1. কিভাবে জাভাস্ক্রিপ্ট দিয়ে ক্যানভাসে আঁকা যায়?

  2. কিভাবে জাভাস্ক্রিপ্ট দিয়ে ক্লিপবোর্ডে টেক্সট কপি করবেন?

  3. জাভাস্ক্রিপ্টে কার্যকর করার সময় একটি ফাংশন কীভাবে বন্ধ করবেন?

  4. কিভাবে জাভাস্ক্রিপ্টে হ্রাস এবং পরিসীমা সহ ফ্যাক্টরিয়াল ফাংশন লিখবেন?