这个是谷歌AI Jemini帮我生成的一个简单网页小工具,保存下源代码,方便后续修改.
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>护照信息工具 - 精确/模糊搜索与格式化</title>
<style>
/* --- 核心布局和颜色 --- */
body {
font-family: Arial, sans-serif;
margin: 20px;
background-color: #f4f4f9;
}
.container {
max-width: 800px;
margin: 0 auto;
background: #fff;
padding: 30px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
h1 {
color: #333;
text-align: center;
border-bottom: 2px solid #eee;
padding-bottom: 10px;
margin-bottom: 20px;
}
label {
/* 默认隐藏 label 的 display: block */
display: inline;
margin-bottom: 0;
font-weight: bold;
color: #555;
}
input[type="text"] {
width: 100%;
padding: 10px;
margin-bottom: 20px;
border: 2px solid #007bff;
border-radius: 4px;
box-sizing: border-box;
font-size: 18px;
letter-spacing: 0.5px;
}
/* --- 紧凑搜索区优化(新样式) --- */
.search-header-row {
display: flex; /* 启用 Flexbox */
justify-content: space-between; /* 左右对齐 */
align-items: center; /* 垂直居中 */
margin-bottom: 5px; /* 减少与输入框的间距 */
}
.exact-match-note {
font-size: 0.9em;
color: #007bff;
font-weight: bold;
padding-left: 10px;
}
/* --- 英文格式化功能区样式 --- */
.format-group {
border: 1px solid #ccc;
padding: 15px;
margin-bottom: 30px;
border-radius: 6px;
background-color: #f8f8f8;
}
.format-input-row {
display: flex;
align-items: center;
gap: 15px;
}
.format-input-row input {
flex-grow: 1;
margin-bottom: 0;
border-color: #28a745;
}
#formattedOutput {
flex-grow: 1;
padding: 10px;
border: 2px solid #007bff;
border-radius: 4px;
background-color: #e9ecef;
font-size: 18px;
color: #333;
user-select: all;
}
.format-group h2 {
margin-top: 0;
color: #28a745;
border-bottom: 1px dashed #ddd;
padding-bottom: 8px;
margin-bottom: 10px;
}
/* --- 搜索结果表格样式 --- */
.country-table-container {
margin-top: 20px;
max-height: 500px;
overflow-y: auto;
border: 1px solid #ddd;
border-radius: 4px;
background-color: #fafafa;
}
.country-table {
width: 100%;
border-collapse: collapse;
}
.country-table th, .country-table td {
padding: 10px 12px;
border: 1px solid #eee;
text-align: left;
}
.country-table th {
background-color: #007bff;
color: white;
position: sticky;
top: 0;
z-index: 10;
}
.country-table td:first-child {
font-weight: bold;
color: #0056b3;
font-family: monospace, sans-serif;
}
.country-table tr:nth-child(even) {
background-color: #f9f9f9;
}
.country-table tr:hover {
background-color: #e0f7fa;
}
.no-results {
text-align: center;
padding: 20px;
color: #d9534f;
font-weight: bold;
}
</style>
</head>
<body>
<div class="container">
<h1>护照信息辅助工具</h1>
<div class="format-group">
<h2>📝 英文格式规范化 (首字母大写)</h2>
<label for="rawInput">输入全大写的英文内容 (如护照上的姓名):</label>
<div class="format-input-row">
<input type="text" id="rawInput" placeholder="例如:ZHANG SANFENG" oninput="formatText()">
</div>
<label for="formattedOutput" style="margin-top: 15px;">规范化结果 (首字母大写):</label>
<div id="formattedOutput"></div>
<small style="color: #6c757d;">适用于护照姓名的标准格式,点击结果可选中复制。</small>
</div>
<div class="search-header-row">
<label for="countryCodeInput">输入代码、英文名或中文名进行搜索:</label>
<p id="search-mode-note" class="exact-match-note">当前模式:模糊搜索 (输入中...)</p>
</div>
<input type="text" id="countryCodeInput" placeholder="输入时模糊搜索,按 Enter(回车) 键精确搜索"
oninput="liveSearch(false)"
onkeydown="handleKeyDown(event)">
<div id="countryListSection">
<h2>🌍 国家代码对照表</h2>
<div class="country-table-container">
<table id="countryListTable" class="country-table">
<thead>
<tr>
<th>三字 / 两字 / 单字母代码</th>
<th>英文名称 (English Name)</th>
<th>中文名称 (Chinese Name)</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
<script>
// 核心数据结构: 存储所有代码类型
const countryData = {
// 示例数据(请确保您的完整数据列表在此处)
"AUT": { english: "Austria", chinese: "奥地利", alpha2: "AT", passport: "A" },
"BEL": { english: "Belgium", chinese: "比利时", alpha2: "BE", passport: "B" },
"CHE": { english: "Switzerland", chinese: "瑞士", alpha2: "CH", passport: "CH" },
"DEU": { english: "Germany", chinese: "德国", alpha2: "DE", passport: "D" },
"ESP": { english: "Spain", chinese: "西班牙", alpha2: "ES", passport: "E" },
"FRA": { english: "France", chinese: "法国", alpha2: "FR", passport: "F" },
"GBR": { english: "United Kingdom of Great Britain and Northern Ireland (The)", chinese: "英国", alpha2: "GB", passport: "GB" },
"ITA": { english: "Italy", chinese: "意大利", alpha2: "IT", passport: "I" },
"USA": { english: "United States of America (The)", chinese: "美国", alpha2: "US", passport: "" },
"CHN": { english: "China", chinese: "中国", alpha2: "CN", passport: "" },
"ARE": { english: "United Arab Emirates (The)", chinese: "阿拉伯联合酋长国", alpha2: "AE", passport: "" },
"AFG": { english: "Afghanistan", chinese: "阿富汗", alpha2: "AF", passport: "" },
"ALA": { english: "Åland Islands", chinese: "奥兰群岛", alpha2: "AX", passport: "" },
"ALB": { english: "Albania", chinese: "阿尔巴尼亚", alpha2: "AL", passport: "" },
"DZA": { english: "Algeria", chinese: "阿尔及利亚", alpha2: "DZ", passport: "" },
"ASM": { english: "American Samoa", chinese: "美属萨摩亚", alpha2: "AS", passport: "" },
"AND": { english: "Andorra", chinese: "安道尔", alpha2: "AD", passport: "" },
"AGO": { english: "Angola", chinese: "安哥拉", alpha2: "AO", passport: "" },
"AIA": { english: "Anguilla", chinese: "安圭拉", alpha2: "AI", passport: "" },
"ATA": { english: "Antarctica", chinese: "南极洲", alpha2: "AQ", passport: "" },
"ATG": { english: "Antigua and Barbuda", chinese: "安提瓜和巴布达", alpha2: "AG", passport: "" },
"ARG": { english: "Argentina", chinese: "阿根廷", alpha2: "AR", passport: "" },
"ARM": { english: "Armenia", chinese: "亚美尼亚", alpha2: "AM", passport: "" },
"ABW": { english: "Aruba", chinese: "阿鲁巴", alpha2: "AW", passport: "" },
"AUS": { english: "Australia", chinese: "澳大利亚", alpha2: "AU", passport: "" },
"AZE": { english: "Azerbaijan", chinese: "阿塞拜疆", alpha2: "AZ", passport: "" },
"BHS": { english: "Bahamas (The)", chinese: "巴哈马", alpha2: "BS", passport: "" },
"BHR": { english: "Bahrain", chinese: "巴林", alpha2: "BH", passport: "" },
"BGD": { english: "Bangladesh", chinese: "孟加拉国", alpha2: "BD", passport: "" },
"BRB": { english: "Barbados", chinese: "巴巴多斯", alpha2: "BB", passport: "" },
"BLR": { english: "Belarus", chinese: "白俄罗斯", alpha2: "BY", passport: "" },
"BLZ": { english: "Belize", chinese: "伯利兹", alpha2: "BZ", passport: "" },
"BEN": { english: "Benin", chinese: "贝宁", alpha2: "BJ", passport: "" },
"BMU": { english: "Bermuda", chinese: "百慕大", alpha2: "BM", passport: "" },
"BTN": { english: "Bhutan", chinese: "不丹", alpha2: "BT", passport: "" },
"BOL": { english: "Bolivia (Plurinational State of)", chinese: "玻利维亚", alpha2: "BO", passport: "" },
"BES": { english: "Bonaire, Sint Eustatius and Saba", chinese: "博内尔、圣尤斯塔蒂乌斯和萨巴", alpha2: "BQ", passport: "" },
"BIH": { english: "Bosnia and Herzegovina", chinese: "波斯尼亚和赫塞哥维那", alpha2: "BA", passport: "" },
"BWA": { english: "Botswana", chinese: "博茨瓦纳", alpha2: "BW", passport: "" },
"BVT": { english: "Bouvet Island", chinese: "布韦岛", alpha2: "BV", passport: "" },
"BRA": { english: "Brazil", chinese: "巴西", alpha2: "BR", passport: "" },
"IOT": { english: "British Indian Ocean Territory (The)", chinese: "英属印度洋领地", alpha2: "IO", passport: "" },
"VGB": { english: "British Virgin Islands", chinese: "英属维尔京群岛", alpha2: "VG", passport: "" },
"BRN": { english: "Brunei Darussalam", chinese: "文莱达鲁萨兰国", alpha2: "BN", passport: "" },
"BGR": { english: "Bulgaria", chinese: "保加利亚", alpha2: "BG", passport: "" },
"BFA": { english: "Burkina Faso", chinese: "布基纳法索", alpha2: "BF", passport: "" },
"BDI": { english: "Burundi", chinese: "布隆迪", alpha2: "BI", passport: "" },
"CPV": { english: "Cabo Verde", chinese: "佛得角", alpha2: "CV", passport: "" },
"KHM": { english: "Cambodia", chinese: "柬埔寨", alpha2: "KH", passport: "" },
"CMR": { english: "Cameroon", chinese: "喀麦隆", alpha2: "CM", passport: "" },
"CAN": { english: "Canada", chinese: "加拿大", alpha2: "CA", passport: "" },
"CYM": { english: "Cayman Islands (The)", chinese: "开曼群岛", alpha2: "KY", passport: "" },
"CAF": { english: "Central African Republic (The)", chinese: "中非共和国", alpha2: "CF", passport: "" },
"TCD": { english: "Chad", chinese: "乍得", alpha2: "TD", passport: "" },
"CHL": { english: "Chile", chinese: "智利", alpha2: "CL", passport: "" },
"CXR": { english: "Christmas Island", chinese: "圣诞岛", alpha2: "CX", passport: "" },
"CCK": { english: "Cocos (Keeling) Islands (The)", chinese: "科科斯(基林)群岛", alpha2: "CC", passport: "" },
"COL": { english: "Colombia", chinese: "哥伦比亚", alpha2: "CO", passport: "" },
"COM": { english: "Comoros (The)", chinese: "科摩罗", alpha2: "KM", passport: "" },
"COD": { english: "Congo (The Democratic Republic of the)", chinese: "刚果(金)", alpha2: "CD", passport: "" },
"COG": { english: "Congo (The)", chinese: "刚果(布)", alpha2: "CG", passport: "" },
"COK": { english: "Cook Islands (The)", chinese: "库克群岛", alpha2: "CK", passport: "" },
"CRI": { english: "Costa Rica", chinese: "哥斯达黎加", alpha2: "CR", passport: "" },
"CIV": { english: "Côte d'Ivoire", chinese: "科特迪瓦", alpha2: "CI", passport: "" },
"HRV": { english: "Croatia", chinese: "克罗地亚", alpha2: "HR", passport: "" },
"CUB": { english: "Cuba", chinese: "古巴", alpha2: "CU", passport: "" },
"CUW": { english: "Curaçao", chinese: "库拉索", alpha2: "CW", passport: "" },
"CYP": { english: "Cyprus", chinese: "塞浦路斯", alpha2: "CY", passport: "" },
"CZE": { english: "Czechia", chinese: "捷克", alpha2: "CZ", passport: "" },
"DNK": { english: "Denmark", chinese: "丹麦", alpha2: "DK", passport: "" },
"DJI": { english: "Djibouti", chinese: "吉布提", alpha2: "DJ", passport: "" },
"DMA": { english: "Dominica", chinese: "多米尼克", alpha2: "DM", passport: "" },
"DOM": { english: "Dominican Republic (The)", chinese: "多米尼加共和国", alpha2: "DO", passport: "" },
"ECU": { english: "Ecuador", chinese: "厄瓜多尔", alpha2: "EC", passport: "" },
"EGY": { english: "Egypt", chinese: "埃及", alpha2: "EG", passport: "" },
"SLV": { english: "El Salvador", chinese: "萨尔瓦多", alpha2: "SV", passport: "" },
"GNQ": { english: "Equatorial Guinea", chinese: "赤道几内亚", alpha2: "GQ", passport: "" },
"ERI": { english: "Eritrea", chinese: "厄立特里亚", alpha2: "ER", passport: "" },
"EST": { english: "Estonia", chinese: "爱沙尼亚", alpha2: "EE", passport: "" },
"SWZ": { english: "Eswatini", chinese: "斯威士兰", alpha2: "SZ", passport: "" },
"ETH": { english: "Ethiopia", chinese: "埃塞俄比亚", alpha2: "ET", passport: "" },
"FLK": { english: "Falkland Islands (The) [Malvinas]", chinese: "福克兰群岛", alpha2: "FK", passport: "" },
"FRO": { english: "Faroe Islands (The)", chinese: "法罗群岛", alpha2: "FO", passport: "" },
"FJI": { english: "Fiji", chinese: "斐济", alpha2: "FJ", passport: "" },
"FIN": { english: "Finland", chinese: "芬兰", alpha2: "FI", passport: "" },
"GUF": { english: "French Guiana", chinese: "法属圭亚那", alpha2: "GF", passport: "" },
"PYF": { english: "French Polynesia", chinese: "法属波利尼西亚", alpha2: "PF", passport: "" },
"ATF": { english: "French Southern Territories (The)", chinese: "法属南部领地", alpha2: "TF", passport: "" },
"GAB": { english: "Gabon", chinese: "加蓬", alpha2: "GA", passport: "" },
"GMB": { english: "Gambia (The)", chinese: "冈比亚", alpha2: "GM", passport: "" },
"GEO": { english: "Georgia", chinese: "格鲁吉亚", alpha2: "GE", passport: "" },
"GHA": { english: "Ghana", chinese: "加纳", alpha2: "GH", passport: "" },
"GIB": { english: "Gibraltar", chinese: "直布罗陀", alpha2: "GI", passport: "" },
"GRC": { english: "Greece", chinese: "希腊", alpha2: "GR", passport: "GR" },
"GRL": { english: "Greenland", chinese: "格陵兰", alpha2: "GL", passport: "" },
"GRD": { english: "Grenada", chinese: "格林纳达", alpha2: "GD", passport: "" },
"GLP": { english: "Guadeloupe", chinese: "瓜德罗普", alpha2: "GP", passport: "" },
"GUM": { english: "Guam", chinese: "关岛", alpha2: "GU", passport: "" },
"GTM": { english: "Guatemala", chinese: "危地马拉", alpha2: "GT", passport: "" },
"GGY": { english: "Guernsey", chinese: "根西岛", alpha2: "GG", passport: "" },
"GIN": { english: "Guinea", chinese: "几内亚", alpha2: "GN", passport: "" },
"GNB": { english: "Guinea-Bissau", chinese: "几内亚比绍", alpha2: "GW", passport: "" },
"GUY": { english: "Guyana", chinese: "圭亚那", alpha2: "GY", passport: "" },
"HTI": { english: "Haiti", chinese: "海地", alpha2: "HT", passport: "" },
"HMD": { english: "Heard Island and McDonald Islands", chinese: "赫德岛和麦克唐纳群岛", alpha2: "HM", passport: "" },
"VAT": { english: "Holy See (The)", chinese: "梵蒂冈", alpha2: "VA", passport: "V" },
"HND": { english: "Honduras", chinese: "洪都拉斯", alpha2: "HN", passport: "" },
"HKG": { english: "Hong Kong", chinese: "中国香港", alpha2: "HK", passport: "" },
"HUN": { english: "Hungary", chinese: "匈牙利", alpha2: "HU", passport: "H" },
"ISL": { english: "Iceland", chinese: "冰岛", alpha2: "IS", passport: "" },
"IND": { english: "India", chinese: "印度", alpha2: "IN", passport: "" },
"IDN": { english: "Indonesia", chinese: "印度尼西亚", alpha2: "ID", passport: "" },
"IRN": { english: "Iran (Islamic Republic of)", chinese: "伊朗", alpha2: "IR", passport: "" },
"IRQ": { english: "Iraq", chinese: "伊拉克", alpha2: "IQ", passport: "" },
"IRL": { english: "Ireland", chinese: "爱尔兰", alpha2: "IE", passport: "IRL" },
"IMN": { english: "Isle of Man", chinese: "马恩岛", alpha2: "IM", passport: "" },
"ISR": { english: "Israel", chinese: "以色列", alpha2: "IL", passport: "" },
"JAM": { english: "Jamaica", chinese: "牙买加", alpha2: "JM", passport: "" },
"JPN": { english: "Japan", chinese: "日本", alpha2: "JP", passport: "" },
"JEY": { english: "Jersey", chinese: "泽西岛", alpha2: "JE", passport: "" },
"JOR": { english: "Jordan", chinese: "约旦", alpha2: "JO", passport: "" },
"KAZ": { english: "Kazakhstan", chinese: "哈萨克斯坦", alpha2: "KZ", passport: "" },
"KEN": { english: "Kenya", chinese: "肯尼亚", alpha2: "KE", passport: "" },
"KIR": { english: "Kiribati", chinese: "基里巴斯", alpha2: "KI", passport: "" },
"PRK": { english: "Korea (The Democratic People's Republic of)", chinese: "朝鲜", alpha2: "KP", passport: "" },
"KOR": { english: "Korea (The Republic of)", chinese: "韩国", alpha2: "KR", passport: "" },
"KWT": { english: "Kuwait", chinese: "科威特", alpha2: "KW", passport: "" },
"KGZ": { english: "Kyrgyzstan", chinese: "吉尔吉斯斯坦", alpha2: "KG", passport: "" },
"LAO": { english: "Lao People's Democratic Republic (The)", chinese: "老挝", alpha2: "LA", passport: "" },
"LVA": { english: "Latvia", chinese: "拉脱维亚", alpha2: "LV", passport: "" },
"LBN": { english: "Lebanon", chinese: "黎巴嫩", alpha2: "LB", passport: "" },
"LSO": { english: "Lesotho", chinese: "莱索托", alpha2: "LS", passport: "" },
"LBR": { english: "Liberia", chinese: "利比里亚", alpha2: "LR", passport: "" },
"LBY": { english: "Libya", chinese: "利比里亚", alpha2: "LY", passport: "" },
"LIE": { english: "Liechtenstein", chinese: "列支敦士登", alpha2: "LI", passport: "" },
"LTU": { english: "Lithuania", chinese: "立陶宛", alpha2: "LT", passport: "" },
"LUX": { english: "Luxembourg", chinese: "卢森堡", alpha2: "LU", passport: "L" },
"MAC": { english: "Macao", chinese: "中国澳门", alpha2: "MO", passport: "" },
"MDG": { english: "Madagascar", chinese: "马达加斯加", alpha2: "MG", passport: "" },
"MWI": { english: "Malawi", chinese: "马拉维", alpha2: "MW", passport: "" },
"MYS": { english: "Malaysia", chinese: "马来西亚", alpha2: "MY", passport: "" },
"MDV": { english: "Maldives", chinese: "马尔代夫", alpha2: "MV", passport: "" },
"MLI": { english: "Mali", chinese: "马里", alpha2: "ML", passport: "" },
"MLT": { english: "Malta", chinese: "马耳他", alpha2: "MT", passport: "M" },
"MHL": { english: "Marshall Islands (The)", chinese: "马绍尔群岛", alpha2: "MH", passport: "" },
"MTQ": { english: "Martinique", chinese: "马提尼克", alpha2: "MQ", passport: "" },
"MRT": { english: "Mauritania", chinese: "毛里塔尼亚", alpha2: "MR", passport: "" },
"MUS": { english: "Mauritius", chinese: "毛里求斯", alpha2: "MU", passport: "" },
"MYT": { english: "Mayotte", chinese: "马约特", alpha2: "YT", passport: "" },
"MEX": { english: "Mexico", chinese: "墨西哥", alpha2: "MX", passport: "" },
"FSM": { english: "Micronesia (Federated States of)", chinese: "密克罗尼西亚", alpha2: "FM", passport: "" },
"MDA": { english: "Moldova (The Republic of)", chinese: "摩尔多瓦", alpha2: "MD", passport: "" },
"MCO": { english: "Monaco", chinese: "摩纳哥", alpha2: "MC", passport: "" },
"MNG": { english: "Mongolia", chinese: "蒙古", alpha2: "MN", passport: "" },
"MNE": { english: "Montenegro", chinese: "黑山", alpha2: "ME", passport: "" },
"MSR": { english: "Montserrat", chinese: "蒙特塞拉特", alpha2: "MS", passport: "" },
"MAR": { english: "Morocco", chinese: "摩洛哥", alpha2: "MA", passport: "" },
"MOZ": { english: "Mozambique", chinese: "莫桑比克", alpha2: "MZ", passport: "" },
"MMR": { english: "Myanmar", chinese: "缅甸", alpha2: "MM", passport: "" },
"NAM": { english: "Namibia", chinese: "纳米比亚", alpha2: "NA", passport: "" },
"NRU": { english: "Nauru", chinese: "瑙鲁", alpha2: "NR", passport: "" },
"NPL": { english: "Nepal", chinese: "尼泊尔", alpha2: "NP", passport: "" },
"NLD": { english: "Netherlands (The)", chinese: "荷兰", alpha2: "NL", passport: "NL" },
"NCL": { english: "New Caledonia", chinese: "新喀里多尼亚", alpha2: "NC", passport: "" },
"NZL": { english: "New Zealand", chinese: "新西兰", alpha2: "NZ", passport: "" },
"NIC": { english: "Nicaragua", chinese: "尼加拉瓜", alpha2: "NI", passport: "" },
"NER": { english: "Niger (The)", chinese: "尼日尔", alpha2: "NE", passport: "" },
"NGA": { english: "Nigeria", chinese: "尼日利亚", alpha2: "NG", passport: "" },
"NIU": { english: "Niue", chinese: "纽埃", alpha2: "NU", passport: "" },
"NFK": { english: "Norfolk Island", chinese: "诺福克岛", alpha2: "NF", passport: "" },
"MNP": { english: "Northern Mariana Islands (The)", chinese: "北马里亚纳群岛", alpha2: "MP", passport: "" },
"NOR": { english: "Norway", chinese: "挪威", alpha2: "NO", passport: "" },
"OMN": { english: "Oman", chinese: "阿曼", alpha2: "OM", passport: "" },
"PAK": { english: "Pakistan", chinese: "巴基斯坦", alpha2: "PK", passport: "" },
"PLW": { english: "Palau", chinese: "帕劳", alpha2: "PW", passport: "" },
"PSE": { english: "Palestine, State of", chinese: "巴勒斯坦", alpha2: "PS", passport: "" },
"PAN": { english: "Panama", chinese: "巴拿马", alpha2: "PA", passport: "" },
"PNG": { english: "Papua New Guinea", chinese: "巴布亚新几内亚", alpha2: "PG", passport: "" },
"PRY": { english: "Paraguay", chinese: "巴拉圭", alpha2: "PY", passport: "" },
"PER": { english: "Peru", chinese: "秘鲁", alpha2: "PE", passport: "" },
"PHL": { english: "Philippines (The)", chinese: "菲律宾", alpha2: "PH", passport: "" },
"PCN": { english: "Pitcairn", chinese: "皮特凯恩", alpha2: "PN", passport: "" },
"POL": { english: "Poland", chinese: "波兰", alpha2: "PL", passport: "" },
"PRT": { english: "Portugal", chinese: "葡萄牙", alpha2: "PT", passport: "P" },
"PRI": { english: "Puerto Rico", chinese: "波多黎各", alpha2: "PR", passport: "" },
"QAT": { english: "Qatar", chinese: "卡塔尔", alpha2: "QA", passport: "" },
"MKD": { english: "Republic of North Macedonia", chinese: "北马其顿", alpha2: "MK", passport: "" },
"ROU": { english: "Romania", chinese: "罗马尼亚", alpha2: "RO", passport: "" },
"RUS": { english: "Russian Federation (The)", chinese: "俄罗斯", alpha2: "RU", passport: "" },
"RWA": { english: "Rwanda", chinese: "卢旺达", alpha2: "RW", passport: "" },
"REU": { english: "Réunion", chinese: "留尼汪", alpha2: "RE", passport: "" },
"BLM": { english: "Saint Barthélemy", chinese: "圣巴泰勒米", alpha2: "BL", passport: "" },
"SHN": { english: "Saint Helena, Ascension and Tristan da Cunha", chinese: "圣赫勒拿、阿森松和特里斯坦-达库尼亚", alpha2: "SH", passport: "" },
"KNA": { english: "Saint Kitts and Nevis", chinese: "圣基茨和尼维斯", alpha2: "KN", passport: "" },
"LCA": { english: "Saint Lucia", chinese: "圣卢西亚", alpha2: "LC", passport: "" },
"MAF": { english: "Saint Martin (French part)", chinese: "法属圣马丁", alpha2: "MF", passport: "" },
"SPM": { english: "Saint Pierre and Miquelon", chinese: "圣皮埃尔和密克隆", alpha2: "PM", passport: "" },
"VCT": { english: "Saint Vincent and the Grenadines", chinese: "圣文森特和格林纳丁斯", alpha2: "VC", passport: "" },
"WSM": { english: "Samoa", chinese: "萨摩亚", alpha2: "WS", passport: "" },
"SMR": { english: "San Marino", chinese: "圣马力诺", alpha2: "SM", passport: "" },
"STP": { english: "Sao Tome and Principe", chinese: "圣多美和普林西比", alpha2: "ST", passport: "" },
"SAU": { english: "Saudi Arabia", chinese: "沙特阿拉伯", alpha2: "SA", passport: "" },
"SEN": { english: "Senegal", chinese: "塞内加尔", alpha2: "SN", passport: "" },
"SRB": { english: "Serbia", chinese: "塞尔维亚", alpha2: "RS", passport: "" },
"SYC": { english: "Seychelles", chinese: "塞舌尔", alpha2: "SC", passport: "" },
"SLE": { english: "Sierra Leone", chinese: "塞拉利昂", alpha2: "SL", passport: "" },
"SGP": { english: "Singapore", chinese: "新加坡", alpha2: "SG", passport: "" },
"SXM": { english: "Sint Maarten (Dutch part)", chinese: "荷属圣马丁", alpha2: "SX", passport: "" },
"SVK": { english: "Slovakia", chinese: "斯洛伐克", alpha2: "SK", passport: "SK" },
"SVN": { english: "Slovenia", chinese: "斯洛文尼亚", alpha2: "SI", passport: "" },
"SLB": { english: "Solomon Islands", chinese: "所罗门群岛", alpha2: "SB", passport: "" },
"SOM": { english: "Somalia", chinese: "索马里", alpha2: "SO", passport: "" },
"ZAF": { english: "South Africa", chinese: "南非", alpha2: "ZA", passport: "" },
"SGS": { english: "South Georgia and the South Sandwich Islands", chinese: "南乔治亚岛和南桑威奇群岛", alpha2: "GS", passport: "" },
"SSD": { english: "South Sudan", chinese: "南苏丹", alpha2: "SS", passport: "" },
"LKA": { english: "Sri Lanka", chinese: "斯里兰卡", alpha2: "LK", passport: "" },
"SDN": { english: "Sudan (The)", chinese: "苏丹", alpha2: "SD", passport: "" },
"SUR": { english: "Suriname", chinese: "苏里南", alpha2: "SR", passport: "" },
"SJM": { english: "Svalbard and Jan Mayen", chinese: "斯瓦尔巴和扬马延", alpha2: "SJ", passport: "" },
"SWE": { english: "Sweden", chinese: "瑞典", alpha2: "SE", passport: "S" },
"SYR": { english: "Syrian Arab Republic", chinese: "叙利亚", alpha2: "SY", passport: "" },
"TWN": { english: "Taiwan (Province of China)", chinese: "中国台湾", alpha2: "TW", passport: "" },
"TJK": { english: "Tajikistan", chinese: "塔吉克斯坦", alpha2: "TJ", passport: "" },
"TZA": { english: "Tanzania, United Republic of", chinese: "坦桑尼亚", alpha2: "TZ", passport: "" },
"THA": { english: "Thailand", chinese: "泰国", alpha2: "TH", passport: "" },
"TLS": { english: "Timor-Leste", chinese: "东帝汶", alpha2: "TL", passport: "" },
"TGO": { english: "Togo", chinese: "多哥", alpha2: "TG", passport: "" },
"TKL": { english: "Tokelau", chinese: "托克劳", alpha2: "TK", passport: "" },
"TON": { english: "汤加", chinese: "汤加", alpha2: "TO", passport: "" },
"TTO": { english: "Trinidad and Tobago", chinese: "特立尼达和多巴哥", alpha2: "TT", passport: "" },
"TUN": { english: "Tunisia", chinese: "突尼斯", alpha2: "TN", passport: "" },
"TUR": { english: "Turkey", chinese: "土耳其", alpha2: "TR", passport: "" },
"TKM": { english: "Turkmenistan", chinese: "土库曼斯坦", alpha2: "TM", passport: "" },
"TCA": { english: "Turks and Caicos Islands (The)", chinese: "特克斯和凯科斯群岛", alpha2: "TC", passport: "" },
"TUV": { english: "Tuvalu", chinese: "图瓦卢", alpha2: "TV", passport: "" },
"UGA": { english: "Uganda", chinese: "乌干达", alpha2: "UG", passport: "" },
"UKR": { english: "Ukraine", chinese: "乌克兰", alpha2: "UA", passport: "" },
"UMI": { english: "United States Minor Outlying Islands (The)", chinese: "美国本土外小岛屿", alpha2: "UM", passport: "" },
"URY": { english: "Uruguay", chinese: "乌拉圭", alpha2: "UY", passport: "" },
"UZB": { english: "Uzbekistan", chinese: "乌兹别克斯坦", alpha2: "UZ", passport: "" },
"VUT": { english: "Vanuatu", chinese: "瓦努阿图", alpha2: "VU", passport: "" },
"VEN": { english: "Venezuela (Bolivarian Republic of)", chinese: "委内瑞拉", alpha2: "VE", passport: "" },
"VNM": { english: "Viet Nam", chinese: "越南", alpha2: "VN", passport: "" },
"VIR": { english: "Virgin Islands (U.S.)", chinese: "美属维尔京群岛", alpha2: "VI", passport: "" },
"WLF": { english: "Wallis and Futuna", chinese: "瓦利斯和富图纳", alpha2: "WF", passport: "" },
"ESH": { english: "Western Sahara", chinese: "西撒哈拉", alpha2: "EH", passport: "" },
"YEM": { english: "Yemen", chinese: "也门", alpha2: "YE", passport: "" },
"ZMB": { english: "Zambia", chinese: "赞比亚", alpha2: "ZM", passport: "" },
"ZWE": { english: "Zimbabwe", chinese: "津巴布韦", alpha2: "ZW", passport: "" }
// 确保您的完整数据列表在此处
};
// 创建一个用于快速模糊搜索的数组 (包含所有代码)
const searchableCountries = Object.keys(countryData).map(code => {
const country = countryData[code];
let extraTerms = "";
// 1. 特殊城市/别名搜索词 (例如迪拜)
if (code === "ARE") {
extraTerms = "Dubai 迪拜 Abu Dhabi 阿布扎比";
}
// 2. 整合所有代码标准到搜索项中
const allCodes = `${code} ${country.alpha2 || ''} ${country.passport || ''}`.trim();
return {
code: code,
alpha2: country.alpha2,
passport: country.passport,
english: country.english,
chinese: country.chinese,
searchTerms: `${allCodes} ${country.english} ${country.chinese} ${extraTerms}`.toLowerCase()
};
});
const tableBody = document.querySelector('#countryListTable tbody');
const searchModeNote = document.getElementById('search-mode-note');
// --- 英文格式化函数 ---
function formatText() {
const rawInput = document.getElementById('rawInput').value.trim();
const outputDiv = document.getElementById('formattedOutput');
if (rawInput === "") {
outputDiv.textContent = "";
return;
}
const lowerCaseText = rawInput.toLowerCase();
const formattedText = lowerCaseText.replace(/(^|\s|-|\')\S/g, function(match) {
return match.toUpperCase();
});
outputDiv.textContent = formattedText;
}
// --- 代码显示格式化函数 ---
function formatCodeDisplay(country) {
const parts = [];
parts.push(country.code);
if (country.alpha2 && country.alpha2 !== country.code) {
parts.push(country.alpha2);
}
if (country.passport && country.passport !== country.code && country.passport !== country.alpha2) {
parts.push(country.passport);
}
return parts.join(' / ');
}
// --- 渲染函数 ---
function renderCountryList(countriesToRender, isExactSearch) {
tableBody.innerHTML = '';
const fragment = document.createDocumentFragment();
if (countriesToRender.length === 0) {
const row = document.createElement('tr');
row.classList.add('no-results');
const td = document.createElement('td');
td.setAttribute('colspan', '3');
td.textContent = isExactSearch ? "未找到完全匹配项。请尝试其他代码。" : "未找到匹配项。请尝试其他代码、英文名或中文名。";
row.appendChild(td);
fragment.appendChild(row);
} else {
countriesToRender.forEach(country => {
const row = document.createElement('tr');
const tdCode = document.createElement('td');
tdCode.textContent = formatCodeDisplay(country);
row.appendChild(tdCode);
const tdEnglish = document.createElement('td');
tdEnglish.textContent = country.english;
row.appendChild(tdEnglish);
const tdChinese = document.createElement('td');
tdChinese.textContent = country.chinese;
row.appendChild(tdChinese);
fragment.appendChild(row);
});
}
tableBody.appendChild(fragment);
}
/**
* 实时搜索国家代码/名称
* @param {boolean} isExact - 是否执行精确搜索(回车键触发)
*/
function liveSearch(isExact) {
const inputElement = document.getElementById('countryCodeInput');
const searchText = inputElement.value.toLowerCase().trim();
let filteredCountries;
let currentSearchMode = isExact ? "精确搜索 (回车)" : "模糊搜索 (输入中...)";
searchModeNote.textContent = `当前模式:${currentSearchMode}`;
if (searchText.length === 0) {
filteredCountries = searchableCountries.sort((a, b) => a.code.localeCompare(b.code));
document.querySelector('#countryListSection h2').textContent = "🌍 所有国家代码对照表";
} else {
if (isExact) {
// --- 精确搜索逻辑 ---
filteredCountries = searchableCountries.filter(country => {
return country.code.toLowerCase() === searchText ||
country.alpha2.toLowerCase() === searchText ||
country.passport.toLowerCase() === searchText ||
country.english.toLowerCase() === searchText ||
country.chinese === searchText;
}).sort((a, b) => a.code.localeCompare(b.code));
} else {
// --- 模糊搜索逻辑 (默认) ---
filteredCountries = searchableCountries.filter(country => {
return country.searchTerms.includes(searchText);
}).sort((a, b) => a.code.localeCompare(b.code));
}
document.querySelector('#countryListSection h2').textContent = `🔎 搜索结果 (匹配 ${filteredCountries.length} 条)`;
}
renderCountryList(filteredCountries, isExact);
}
/**
* 处理输入框的按键事件
* @param {Event} event
*/
function handleKeyDown(event) {
if (event.key === 'Enter') {
event.preventDefault();
liveSearch(true); // 触发精确搜索
}
}
// 页面加载完成后,初始化两个功能
document.addEventListener('DOMContentLoaded', () => {
liveSearch(false);
formatText();
});
</script>
</body>
</html>