如何获取文本框输出来操作JS? [英] How do I take output of textbox to manipulate JS?

查看:91
本文介绍了如何获取文本框输出来操作JS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,在你试过了什么?是我目前的代码。我想知道是否有人可以帮助我这样做,所以出现一个文本框,当你粘贴一个processing.js代码时,它输出一个图纸。如果这是有道理的。



基本上,



fill(255,255,0);

ellipse(200,200,200,200);

noFill();

stroke(0,0,0);

strokeWeight(2);

arc(200,200,150,100,0,PI);

fill(0,0,0);

ellipse(250,200,10,10);

ellipse(153,200,10,10);



将是一个函数,它接受文本框的输出并运行该文本框的输出。



因此文本框会打开,你可以输入...



椭圆(200,200,200,200);



和圆圈会出现在点击上。请有人写这个或帮助那将是伟大的。 IDK如果你需要像jquery但可能会打破







我尝试过什么:



<!DOCTYPE html>







< canvas id =mycanvas>

Okay so in the "What have you tried?" is the code I currently have. I was wondering if anyone could help me make it so a text box appears and when you paste a processing.js code it outputs a drawing. If that makes sense.

Basically,

fill(255, 255, 0);
ellipse(200, 200, 200, 200);
noFill();
stroke(0, 0, 0);
strokeWeight(2);
arc(200, 200, 150, 100, 0, PI);
fill(0, 0, 0);
ellipse(250, 200, 10, 10);
ellipse(153, 200, 10, 10);

would be a function that takes the output of textbox and runs the output of that text box.

So a text box would open up and you could type in...

ellipse(200, 200, 200, 200);

and a circle would appear on a click. PLEASE someone write this or help that would be great. IDK if you need like jquery but that might break the



What I have tried:

<!DOCTYPE html>



<canvas id="mycanvas">

推荐答案

你的问题不是'非常清楚。您似乎想要创建一个包含文本框和Canvas的网页。您希望用户能够在文本框中键入一些恰好是javascript代码的文本,并执行该JS代码。它也恰好是感兴趣的JS将画入画布。



假设我的解释是正确的,你可以使用标准的JS函数实现这一点的eval 。例如:



var command =fill(255,255,0); \

ellipse(200,200,200, 200); \

noFill(); stroke(0,0,0); \

strokeWeight(2); \

arc(200,200,150,100,0,PI); \

fill(0,0,0); \

ellipse(250,200 ,10,10); \

ellipse(153,200,10,10);;



eval(command);



应该大致达到你想要的效果,当然你需要从文本框中获取命令字符串并将其传递给eval命令,设置画布。
Your question isn't very clear. It seems that you want to create a web page containing a text box and a Canvas. You want a user to be able to type some text that happens to be javascript code into the text box, and for that JS code to execute. It also happens to be the case that the JS of interest will paint into the Canvas.

Assuming that my interpretation is right, you can achieve this using the standard JS function eval. For example:

var command = "fill(255, 255, 0); \
ellipse(200, 200, 200, 200); \
noFill(); stroke(0, 0, 0); \
strokeWeight(2); \
arc(200, 200, 150, 100, 0, PI); \
fill(0, 0, 0); \
ellipse(250, 200, 10, 10); \
ellipse(153, 200, 10, 10);";

eval(command);

should achieve roughly what you want, but of course you'll need to get the "command" string from your text box and pass this to the eval command, and set-up the Canvas.


这篇关于如何获取文本框输出来操作JS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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