javascript - 一个框架 - 如何单击一个框并设置功能
问题描述
我想要它,这样当我单击场景中的一个框时,它会运行一个功能
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
解决方案
试试这个 JS 代码,应该可以解决你的问题:
const paragraphs = document.getElementsByTagName('p');
for (paragraph of paragraphs) {
paragraph.addEventListener('click', function(e) {
console.log("Hello it worked!")
})
}
推荐阅读
- node.js - Dialogflow - Google Assistant:显示带有图标+文字的建议
- php - 缓存单选按钮jquery
- android - 如何解决 fopen64、freopen64、tmpfile64 未声明错误?
- php - 使用学说将浏览量保存在数据库中的最快方法
- azure - 访问麦克风读数以进行粗略的分贝测量
- python - OpenCV-ArUco中tvecs rvecs的基本理解
- css - 标题上的任意高度 + 容器上的其余高度
- c# - C#实体框架查询存储过程报错“不支持文化”
- r - R:重复计算具有不同参数的字符串中的单词的函数
- javafx - 将多个图像保存在一个 png 文件中