本文介绍了如何从HTML调用Processing.js函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究HTML5和Processing.js。

当用户点击我网页上的图片时,我想在Processing.js代码中调用一个函数。只需在 onclick 中调用该函数即可,如下面这个简单示例所示:

 
< html>
< head>
< script language =javascriptsrc =processing.init.js>< / script>
< script language =javascriptsrc =processing.js>< / script>
< / head>
< body>
< script type =application / processing>
void restart()
{/ *做某事* /}
< / script>< canvas>
您需要支持HTML5的浏览器才能看到此内容。
< / canvas>< br />< br />
< img src =restart-image.pngonclick =restart()>
< / body>
< / html>



任何有关如何在Processing.js脚本中调用方法的想法图像被点击? (也许我正在通过使用 img onclick ?来制作一个基本的HTML错误。)

解决方案

这应该起作用,将你的图像放在锚标记< a> image< / a>
使用href标记来调用函数。

 < ; a href =javascript:restart()>图片来源< / a> 


I'm exploring HTML5 and Processing.js.

When the user clicks on an image on my webpage, I'd like to call a function in the Processing.js code. Just calling the function in onclick, as illustrated in this simple example, isn't working:

<html>
  <head>
    <script language="javascript" src="processing.init.js"></script>
    <script language="javascript" src="processing.js"></script>
  </head>
  <body>
    <script type="application/processing">
    void restart()
    { /* does something */ }
    </script><canvas>
      You'll need a browser that supports HTML5 to see this content.
    </canvas><br/><br/>
    <img src="restart-image.png" onclick="restart()">
  </body>
</html>

Any thoughts on how I can call a method in the Processing.js script when an image is clicked? (Maybe I'm making a basic HTML mistake by using img onclick?)

解决方案

This should work, enclose you image inside the anchor tag <a> image </a>Use href tag to call the function.

<a href="javascript:restart()"> image source </a>

这篇关于如何从HTML调用Processing.js函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 19:20