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 = ''; // 清空输入框的内容
return;
}
if (inputValue.length === 9) {
// 执行搜索操作
performSearch(inputValue);
}
});
function performSearch(keyword) {
// 在这里执行搜索操作
console.log('搜索关键词:', keyword);
}
这是一个例子