有没有办法在页面加载时创建内置的 HTML 5 拼写检查测试字段?我想将此功能添加到现有的 Intranet 站点,以便在用户加载表单时显示拼写错误。
似乎是在用户键入无效值时显示拼写错误。我正在尝试显示之前保存然后提供给页面的无效值。
这可能吗? 谢谢ST
最佳答案
...
<script>
var e;
function spell()
{
var sp = document.getElementById('sp');
var sel = window.getSelection();
sel.selectAllChildren(sp);
e = sel.getRangeAt(0);
select(sp, e.startOffset);
return true;
}
function select(sp, i)
{
var sel = window.getSelection();
if (i >= e.endOffset) return true;
var r = document.createRange();
r.setStart(sp, i);
r.setEnd(sp, i);
i++;
sel.removeAllRanges();
sel.addRange(r);
setTimeout(function() {select(sp, i)}, 20);
return true;
}
</script>
</head>
<body onload="spell();" >
<div id="sp" spellcheck="true" contenteditable="true">
...
这对我适用于 Chrome。它有点难看,你看到光标在可编辑的 div 中移动,但它完成了工作。
关于页面加载时的 HTML 5 拼写检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43257072/