首页 > 解决方案 > 一个框架 - 如何单击一个框并设置功能

问题描述

我想要它,这样当我单击场景中的一个框时,它会运行一个功能

document.querySelector('p').addEventListener('click', function (evt) {
    console.log('This element was clicked!');
});

我试过了,但它不工作

此外,您可以查看https://aframe.io/docs/0.8.0/introduction/interactions-and-controllers.html

标签: javascriptaframe

解决方案


试试这个 JS 代码,应该可以解决你的问题:

const paragraphs = document.getElementsByTagName('p');

for (paragraph of paragraphs) {
  paragraph.addEventListener('click', function(e) {
  console.log("Hello it worked!")
 })
}

推荐阅读