trim 处理字串前后空格

slice取特定范围字串

indexOf 查找字串位置

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>字串处理</title>
</head>
<body>
<input type="email" value="123456789@gmail.com" class="emailInput" />

<button class="submit">送出</button>

<script>
const emailInput = document.querySelector(".emailInput");

console.log(emailInput);

const submit = document.querySelector(".submit");

console.log(submit);

submit.addEventListener("click", () => {
const Textrim = emailInput.value.trim();
const TextNotrim = emailInput.value;
console.log("处理前后字串空格",Textrim); // 处理前后字串空格
console.log("没有处理前后字串空格",TextNotrim); // 没有处理前后字串空格

const SliceText = emailInput.value.slice(0, 5); // 处理起始0 - 5位置的字串
const SliceText2 = emailInput.value.slice(3); // 处理起始3位置的字串
console.log("slice 0-5位置",SliceText);
console.log("slice 0-5位置",SliceText2);

const index = emailInput.value.indexOf("@");
console.log("查找@置",index);

});
</script>
</body>
</html>