HTMLElement.blur()
HTMLElement.blur()
メソッドは、現在の要素からキーボードフォーカスを取り除きます。
構文
element.blur();
例
テキスト入力からフォーカスを取り除く
HTML
<input type="text" id="myText" value="サンプルテキスト">
<br><br>
<button type="button" onclick="focusInput()">クリックするとフォーカスを得ます</button>
<button type="button" onclick="blurInput()">クリックするとフォーカスを失います</button>
JavaScript
function focusInput() {
document.getElementById('myText').focus();
}
function blurInput() {
document.getElementById('myText').blur();
}
結果
仕様書
Specification |
---|
HTML Standard # dom-blur-dev |
ブラウザーの互換性
BCD tables only load in the browser