Disable spell-checking on HTML textfields

前端 未结 6 978
萌比男神i
萌比男神i 2020-11-28 02:27

Can I somehow disable spell-checking on HTML textfields (as seen in e.g. Safari)?

6条回答
  •  半阙折子戏
    2020-11-28 02:35

    The following code snippet disables it for all textarea and input[type=text] elements:

    (function () {
        function disableSpellCheck() {
            let selector = 'input[type=text], textarea';
            let textFields = document.querySelectorAll(selector);
    
            textFields.forEach(
                function (field, _currentIndex, _listObj) {
                    field.spellcheck = false;
                }
            );
        }
    
        disableSpellCheck();
    })();
    

提交回复
热议问题