字符串方法:split() startsWith() includes() trim()
<script>
// split() startsWith() includes() trim()
// split()
const str = "vite,pinia,typescript";
let wrap = document.querySelector('.wrap');
wrap.innerHTML = str.split(',').map(item => `<div>【赠品】${item}</div>`).join('');
// startsWith()
const url = 'https://www.baidu.com';
console.log(url.startsWith('https')); // true
// includes()
console.log(url.includes('baidu')); // true
// trim()
let inp = document.querySelector('input');
document.querySelector('button').addEventListener('click', function () {
if (inp.value.trim() === '') {
return alert('用户名不能为空');
}
});
</script>