→ gasbomb: ? 你這個code不用轉啊 ts的api跟js一樣只是多了靜態型別 06/28 00:57
※ 編輯: u9423504 (42.73.65.64 臺灣), 06/28/2022 11:07:28
※ 編輯: u9423504 (42.73.65.64 臺灣), 06/28/2022 11:11:26
https://reurl.cc/vdzXkN
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.137.116.95 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Ajax/M.1656318837.A.6CA.html
各位前輩、先進們好:
小弟目前在學Angular,遇到以下JavaScript Code不曉得要如何轉為TypeScript:
(() => {
'use strict'
const forms = document.querySelectorAll('.needs-validation')
// Loop over them and prevent submission
Array.from(forms).forEach(form => {
form.addEventListener('submit', event => {
if (!form.checkValidity()) {
event.preventDefault()
event.stopPropagation()
}
form.classList.add('was-validated')
}, false)
})
})()
--------------------------------------------------------------
疑惑如下:
1.Array.from,其對應的TypeScript API為何?!
2.from.addEventListener,其對應的TypeScript API為何?!
3.form.classList.add(), 其對應的TypeScrip API為何?!
有用線上編輯器寫了對應的ts code,但執行仍有錯誤,
附上StackBlitz 上的程式碼連結,還請前輩、先進不吝賜覆。