「javascript」 htmlの autofocus 属性を使用するサンプル

2021年8月20日

説明
HTMLSelectElement.autofocus プロパティは、 HTML の autofocus 属性を反映した true または false の値を持ちます。

使用例1

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<select id="itemSelect" autofocus>
<option>項目 1</option>
<option>項目 2</option>
</select>
JSコード
var hasfocus = document.getElementById('itemSelect').autofocus;
<select id="itemSelect" autofocus> <option>項目 1</option> <option>項目 2</option> </select> JSコード var hasfocus = document.getElementById('itemSelect').autofocus;
<select id="itemSelect" autofocus>
  <option>項目 1</option>
  <option>項目 2</option>
</select>

JSコード
var hasfocus = document.getElementById('itemSelect').autofocus;

使用例2

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<div id="Ta"
<input type="hidden" autofocus="autofocus" />
</div>
<div id="Ta" <input type="hidden" autofocus="autofocus" /> </div>
<div id="Ta"
   <input type="hidden" autofocus="autofocus" />
</div>

 

JavaScript

Posted by arkgame