const searchInput = document.getElementById('search-input');
searchInput.addEventListener('input', function(event) {
const inputValue = event.target.value;
if (!/^\d{1,9}$/.test(inputValue)) {
event.target.value = ''; // 清空輸入框的內(nèi)容
return;
}
if (inputValue.length === 9) {
// 執(zhí)行搜索操作
performSearch(inputValue);
}
});
function performSearch(keyword) {
// 在這里執(zhí)行搜索操作
console.log('搜索關(guān)鍵詞:', keyword);
}
這是一個(gè)例子