form.acceptCharset 對應 HTML accept-charset 屬性,指定表單提交時使用的字符編碼(如 UTF-8、ISO-8859-1)。
<form id="frm1" accept-charset="ISO-8859-1">
<input name="fname" value="Donald">
<input name="lname" value="Duck">
</form>
<script>
console.log(document.getElementById('frm1').acceptCharset); // "ISO-8859-1"
</script>
<meta charset="UTF-8">)。Content-Type 中的 charset 正確解碼。<!-- 頁面聲明 -->
<meta charset="UTF-8">
<!-- 表單無需指定 accept-charset,繼承頁面編碼 -->
<form action="/api/submit" method="post">...</form>
統一 UTF-8 可避免 99% 編碼亂碼問題。
acceptCharset 讀寫表單提交編碼,現代開發統一使用 UTF-8,通常無需顯式設置。維護舊系統時注意編碼一致性:頁面、表單、服務端、數據庫四端統一。