【发布时间】:2020-02-19 23:24:02
【问题描述】:
//const choices = ['Rock', 'Paper', 'Scissors'] in image form
const choices = window.document.getElementsByClassName('Images');
console.log(choices)
var userInput = window.document.getElementsByTagName('input')
console.log(userInput)
//take the image input and use it as a variable for the playerSelection part.
function playerSelection() {
let answer = prompt('Rock, paper, scissors').toLowerCase()
return answer
}
<div class="Options">
<input type ="image" class="Images" src ="https://image.flaticon.com/icons/svg/925/925141.svg" alt=""/>
<input type ="image" class="Images" src="https://image.flaticon.com/icons/svg/2583/2583491.svg" alt style="padding-left: 50px; padding-right: 50px;">
<input type ="image" class="Images" src="https://image.flaticon.com/icons/svg/494/494672.svg" alt="">
</div>
所以我要做的是在用户单击其中一张图片时从 HTML 文件中获取用户输入。所以我以后可以在我的 javascript 文件中使用它并将其保存到一个变量中。我已经尝试过 getElementsByTagName 但开发人员控制台中没有真正显示任何内容。我不确定如何使用谷歌开发者工具测试用户输入,以便我知道我的代码运行正常。
【问题讨论】:
-
你知道如何监听元素上的
click事件吗?
标签: javascript html dom syntax