'; }); container.innerHTML = html; // 点击快速查询 document.querySelectorAll('.plate-grid-item').forEach(function(el) { el.addEventListener('click', function() { var code = el.dataset.code; document.getElementById('cp').value = code; document.getElementById('f').dispatchEvent(new Event('submit')); }); }); } renderPlateTable(); // 查询 document.getElementById('f').addEventListener('submit', function(e) { e.preventDefault(); var input = document.getElementById('cp').value.trim().toUpperCase(); var errorEl = document.getElementById('error-msg'); var cardEl = document.getElementById('result-card'); var plateNumEl = document.getElementById('plate-number'); var plateInfoEl = document.getElementById('plate-info'); if (!input) { errorEl.textContent = '请输入车牌号'; errorEl.classList.add('show'); cardEl.classList.remove('show'); return; } var p1 = input[0]; var p2 = input[1] || ''; // 高亮表格中匹配的项 document.querySelectorAll('.plate-grid-item.highlight').forEach(function(el) { el.classList.remove('highlight'); }); // 优先精确匹配前两位 if (p2 && PLATE_DB[p1 + p2]) { var city = PLATE_DB[p1 + p2]; var province = PROVINCES[p1] || p1; plateNumEl.textContent = input; plateInfoEl.innerHTML = '
省份:' + province + '
' + '
城市:' + city + '
'; cardEl.classList.add('show'); errorEl.classList.remove('show'); // 高亮 var matchEl = document.querySelector('.plate-grid-item[data-code="' + p1 + p2 + '"]'); if (matchEl) matchEl.classList.add('highlight'); cardEl.scrollIntoView({ behavior: 'smooth', block: 'nearest' }); return; } // 回退到省份匹配 if (PROVINCES[p1]) { plateNumEl.textContent = p1; plateInfoEl.innerHTML = '
省份:' + PROVINCES[p1] + '
' + '
说明:请输入完整车牌号(如 ' + p1 + 'A)以查询具体城市
'; cardEl.classList.add('show'); errorEl.classList.remove('show'); cardEl.scrollIntoView({ behavior: 'smooth', block: 'nearest' }); return; } // 未找到 errorEl.textContent = '未找到该车牌信息,请检查输入是否正确'; errorEl.classList.add('show'); cardEl.classList.remove('show'); }); })();