[请告知如何在JS中将下一个功能转换为箭头功能。该代码用于检查电子邮件验证。
function checkGmail() {
let emailvalidation = document.getElementById('email').value;
if (emailvalidation.length < 12) {
document.getElementById('site-heading').style.color = "red";
} else if (emailvalidation.indexOf('@gmail.com') == -1) {
document.getElementById('site-heading').style.color = "red";
} else if (emailvalidation.indexOf('.') < emailvalidation.length - 4) {
document.getElementById('site-heading').style.color = "red";
} else {
document.getElementById('site-heading').style.color = "green";
}
}
将其转换为箭头功能很简单,只需更改此:
function checkGmail() {
// your code logic in here
}
to
const checkGmail = () => {
// your code logic in here
}