javascript - 如何在 ES6 中编写 javascript 函数
问题描述
我一直在创建一个 Web 应用程序,并使用两个不同的 DIV 将注册页面和登录页面组合在同一个 HTML 文件中。当页面加载时,“登录 Div”是唯一可见的,当您单击注册时使用一些 JavaScript 的“Register Div is Showed”。所以它工作正常,但我想在 ES6 中编写这些函数。我该怎么做?
function Registration()
{
const element = document.querySelector(".Registration-form"); // to give a class to the button
const element2=document.querySelector(".login-form");
var unhide=element.style.display="block";
var hider=element2.style.display="none";
}
function login()
{
const element = document.querySelector(".login-form"); // to give a class to the button
const element2 = document.querySelector(".Registration-form"); // to give a class to the button
var unhide=element.style.display="block";
var hider=element2.style.display="none";
}
解决方案
通过一些谷歌搜索,我很确定你可以看到,但这里是:
const registration =() => {
const element = document.querySelector(".Registration-form");
const element2=document.querySelector(".login-form");
const unhide=element.style.display="block";
const hider=element2.style.display="none";
}
const login = () => {
const element = document.querySelector(".login-form"); // to give a class to the button
const element2 = document.querySelector(".Registration-form"); // to give a class to the button
const unhide=element.style.display="block";
const hider=element2.style.display="none";
}
这些类型的函数称为箭头/胖箭头函数。您应该阅读它们,因为在某些情况下它们不能用作意图。
推荐阅读
- c# - 从nuget cli安装包时如何指定依赖包的源?
- excel - Microsoft Excel:宏:VBA:创建对象 Lisy
- java - 如何对 Spring @PreAuthorize(hasAuthority) 进行单元测试?
- javascript - 使用 API 将文本渲染到 div 时,offsetHeight 返回 0
- c# - c# 运算符 '??' 并作为'
- python - 从两个列表创建最小组
- uno-platform - 向情节提要添加重复行为和持续时间时出现 Wasm 异常
- java - Spring MVC 无法显示静态资源
- python-3.x - Pip 在 windows 的 cmd 中不被识别为外部命令
- excel - 返回列中第一个非空单元格中的值直接向左并向上