如何让js funtion运行一次? [英] How should I make js funtion run once?

查看:104
本文介绍了如何让js funtion运行一次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在2个盒子之间绘制一条线,但只需要一次,每当我再次点击时,我看到线条变得越来越厚。我真的需要执行它一次,因为我需要将它保存到数据库,我不想要冗余数据,如果它在执行时一直保存/绘图。



var try1 = true

window.addEventListener(keydown,check,false&& try1 == true);

function check(key){

if(key.keyCode ==65){





c.beginPath();

c.moveTo(150,150);

c.lineTo(300,150);

c.strokeStyle =red;

c.stroke();

try1 = false;

}}



我尝试了什么:



我在链接中尝试了什么,并尝试使用af进行循环。我很遗憾没有成功!!!



I need to draw a line between 2 boxes, but only once, whenever i click again, i see the line is getting thicker and thicker. I really need to execute it once cause later on I need to save it to a db, and I dont want redundant data, if it keeps saving/drawing when its executed.

var try1 = true
window.addEventListener("keydown",check,false && try1 ==true);
function check(key) {
if (key.keyCode == "65") {


c.beginPath();
c.moveTo(150,150);
c.lineTo(300,150);
c.strokeStyle ="red";
c.stroke();
try1 = false;
}}

What I have tried:

I tried whats in the link, and tried to use af for loop. I sadly didnt succeed yet!!!

推荐答案

检查方法中的try1检查



Put the "try1" check in the check method

var try1 = true
window.addEventListener("keydown",check);
function check(key) {
if (try1 == true && key.keyCode == "65") {


这篇关于如何让js funtion运行一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆