###### tags:`ALPHACampWeek6_學期2-2` 搜尋欄頁作:判斷空字串&比對字串&消除默認動作 === 判斷input是否為空字串 --- ```jsx= const keyword = searchInput.ariaValueMax.trim().toLowerCase(); if(!keyword.length){ return alert('Please enter a valid string') } ``` 比對字串 --- - includes ```jsx= const str = 'AC Genie is so cute' console.log(str.includes('Genie')) // true console.log(str.includes('genie')) // false console.log(str.includes('e is')) // true console.log(str.includes('ut')) // true ``` - match ```jsx= else if (event.target.match('.btn-add-favorite')) { addToFavorite(parseInt(event.target.dataset.id)) } ``` - event.matches ```jsx= if (event.target.matches('.btn-add-favorite')) { // console.log(event.target) // console.log(parseInt(event.target.dataset.id)) addToFavorite(parseInt(event.target.dataset.id)) } ``` 消除默認動作 --- ```jsx= event.preventDefault(); ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up