博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
dom5秒计时截断_使用DOM时计时的重要性
阅读量:2507 次
发布时间:2019-05-11

本文共 1820 字,大约阅读时间需要 6 分钟。

dom5秒计时截断

While working with the students in my bootcamp I helped a few of them navigate one problem: timing.

与我的训练营中的学生一起工作时,我帮助了一些人解决了一个问题:时间安排。

In particular, there’s one thing that might not be apparent at first.

特别是,有一件事一开始可能并不明显。

When you access the value of a DOM element and you store it into a variable, that variable is NOT going to be updated with the new value when the DOM element changes.

当您访问DOM元素的值并将其存储到变量中时,当DOM元素更改时,该变量将不会使用新值进行更新。

Suppose you have an input field in a form <input id="temperature">, and you get its value in this way:

假设您有一个格式为<input id="temperature">的输入字段,并且可以通过以下方式获取其值:

const temperature = document.querySelector('input#temperature').value

The temperature variable gets the value of the state of the input field at the moment the browser executes this statement, and then the value stays the same forever.

temperature变量在浏览器执行此语句时获取输入字段的状态值,然后该值永远保持不变。

This is why you can’t do like this:

这就是为什么您不能这样做:

const temperature = document.querySelector('input#temperature').valuedocument.querySelector('form')        .addEventListener('submit', event => {  //send the temperature value to your server})

but you need to access the temperature value when you submit the form:

但提交表格时,您需要访问温度值:

document.querySelector('form')        .addEventListener('submit', event => {  const temperature = document.querySelector('input#temperature').value  //send the temperature value to your server})

Alternatively you can store the input field reference in a variable, and use that to access its value at submit:

或者,您可以将输入字段引用存储在变量中,并使用该变量在提交时访问其值:

const temperatureElement = document.querySelector('input#temperature')document.querySelector('form')        .addEventListener('submit', event => {  const temperature = temperatureElement.value  //send the temperature value to your server})

翻译自:

dom5秒计时截断

转载地址:http://yamgb.baihongyu.com/

你可能感兴趣的文章
VMware下centos7安装VMware Tools
查看>>
Eclipse下Android开发的问题:Failed to install AndroidPhone.apk on device 'emulator-5554': timeout 解决办法...
查看>>
[luogu_P2045]方格取数加强版
查看>>
android 代理模式创建Activity
查看>>
c++课程设计之菜单选择\\
查看>>
iOS 的 XMPPFramework 简介
查看>>
hdu 3555 数位dp入门
查看>>
Git学习系列-Git基本概念
查看>>
c#多个程序集使用app.config 的解决办法
查看>>
模仿网站登录注册
查看>>
Linux+Apache+PHP+MySQL服务器环境配置(CentOS篇)
查看>>
Linux下获取本机IP地址的代码
查看>>
(C#)调用Webservice,提示远程服务器返回错误(500)内部服务器错误
查看>>
flex布局
查看>>
python-----python的文件操作
查看>>
字节流例子
查看>>
Chain Of Responsibility Design Pattern Example
查看>>
Windows下curl使用 转载
查看>>
一个简单最大正向匹配(Maximum Matching)MM中文分词算法的实现
查看>>
angularjs中$scope是什么意思?
查看>>