English 中文(简体)
如何避免在提供投入之前选择投入要素?
原标题:How to avoid selecting input elements before they are made?

给我造成麻烦的守则是:

btn.addEventListener( click , ()=> {
  if (!gamePlay) {
    gamePlay=true
    btn.innerHTML="Check Combo"
    makeGame(6)
  } else { 
    const inputs=Array.from(document.querySelectorAll( input ))
    for (let i=0; i<inputs.length; i++) {
      if (inputs[i].value!==inputs[i].correct) {
        instructions.innerHTML=`Guesses ${++guesses}`
        console.log(inputs[i].value)
        return
      } else {
        instructions.innerHTML=`It took you ${guesses} to win`
      }
    }
  }
})

在用户改变任何数值之前,它明确选择了投入要素。 在用户改变了数字价值之后,我如何调整该守则,以便该方案能够掌握投入内容? 我认为,这只是因为我把这一守则放在太早的时候。

因此,即使用户享有组合权,投入价值都是空洞的,因此,你永远不会去掉。

谁能解释所发生的情况以及如何纠正这种情况?

最佳回答

在用户改变任何数值之前,它明确选择了投入要素。

这不是事实,但如果是的话,那是不会的。 最重要的事情是:exist。 当他们被挑选时,他们就是这样做的。

As a result, even if the user gets the combination right, the input values are all empty

页: 1 他们不是空的,是正确的。

真正的问题是,<代码>更正财产是:

el.correct=Math.floor(Math.random()*5)+1

http://www.un.org。

if (inputs[i].value!==inputs[i].correct) {

这是一种扼杀。 !=要求其操作方式相同。 将价值转换成一个数字比较:

if (Number(inputs[i].value) !== inputs[i].correct) {

https://jsfiddle.net/xw8jsteq/1/"rel=“nofollow noreferer”>updated jsFiddle

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签