來源bootstrap網站
https://getbootstrap.com/docs/5.3/forms/validation/
(() => {.....})()
提問1 轉換成傳統的function函式會是什麼樣?
提問2 尾端的() 是什麼作用?
(() => {
'use strict'
const forms = document.querySelectorAll('.needs-validation')
Array.from(forms).forEach(form => {
form.addEventListener('submit', event => {
if (!form.checkValidity()) {
event.preventDefault()
event.stopPropagation()
}
form.classList.add('was-validated')
}, false)
})
})()
學一下Javascript的ES6語法
https://www.w3schools.com/js/js_es6.asp
這是所謂的立即函數
也就是直接執行的函數
參考
第一個()是 匿名函數宣告
第二的()是 立即調用該函數
(function (){})();
(()=>{})();
(...)();
這是 js 的立即函示
可參考這篇:https://developer.mozilla.org/zh-TW/docs/Glossary/IIFE
Great insights!For those looking for professional assistance, I highly recommend the CV Writer Service from CV Folks. Their expert writers ensure your CV not only highlights your skills but also stands out to potential employers. Check them out for top-notch CV help!