「JavaScript」自動補完(autocomplete)を無効(off)にするサンプル

2021年8月19日

書式
document.getElementById(xxx).setAttribute(“AutoComplete","off")

使用例1

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function completeOffFunc() {
document.getElementById('password').setAttribute("AutoComplete","off")
}
function completeOffFunc() { document.getElementById('password').setAttribute("AutoComplete","off") }
function completeOffFunc() {
  document.getElementById('password').setAttribute("AutoComplete","off")
}

使用例2
フォームの自動補完を無効

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<form method="post" action="/form" autocomplete="off">
xxx
</form>
<form method="post" action="/form" autocomplete="off"> xxx </form>
<form method="post" action="/form" autocomplete="off">
xxx
</form>

使用例3
特定の要素に指定

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<input type="text" id="pwd" name="pwd" autocomplete="off">
<input type="text" id="pwd" name="pwd" autocomplete="off">
<input type="text" id="pwd" name="pwd" autocomplete="off">

 

JavaScript

Posted by arkgame