You need to enable JavaScript to run this app. 设置textarea的spellcheck属性为false后无法消除拼写检查红下划线
优惠活动
大模型
产品
解决方案
定价
更多

设置textarea的spellcheck属性为false后无法消除拼写检查红下划线

textarea动态切换spellcheck属性的兼容性测试结果

我尝试在<textarea spellcheck='true'>和<textarea spellcheck='false'>两种状态间切换,不同浏览器表现如下:

  • Chrome浏览器:一旦设置过spellcheck=true就无法“取消”该功能,即便后续将属性设为false,拼写检查的红色下划线也不会消失*(至少在macOS系统上存在该问题)*
  • Firefox浏览器:表现符合预期
  • Safari浏览器:表现逻辑尚不明确,仅在点击交互时会出现红色下划线,且出现后无法消除

我猜测该问题可能与操作系统相关,欢迎提供其他操作系统下的测试反馈。

复现问题的代码示例

JavaScript代码

const textarea = document.querySelector("textarea");
const form = document.querySelector("form");
const output = document.getElementById("output");

textarea.focus();

form.addEventListener("change", (e) => {
 const trueOrFalse = e.target.value;
 textarea.focus();
 textarea.setAttribute("spellcheck", trueOrFalse);
 output.textContent = textarea.parentNode.innerHTML;
});

CSS代码

body {
  font: 16px/140% monospace;
  background: #eee;
  color: #777;
  padding: 60px;
}

textarea {
 margin: 32px 0;
 width: 320px;
 height: 120px;
 font-size: 16px;
}

label {
 color: #777;
 cursor: pointer;
}

input[type="radio"]:checked + span {
  color: #000
}

HTML代码

<form>
  <label>
    <input type="radio" value="true" name="spellcheck" />
    <span>spellcheck true</span>
  </label>
  <label>
  <input type="radio" value="false" name="spellcheck" checked />
   <span>spellcheck false</span>
  </label>
</form>
<div>
  <textarea spellcheck="false">Here is an example of a misspeltz word</textarea>
</div>

<div id="output">
</div>

内容的提问来源于stack exchange,提问作者methodofaction

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.18 08:36:07