Thuộc tính autofocus của <input type="radio"> xác định nút radio có tự động nhận focus khi trang tải hay không. Giá trị boolean: true (focus) hoặc false (mặc định).
Cú pháp
radioObject.autofocus = true|false
Ví dụ
Kiểm tra autofocus của radio button:
<!DOCTYPE html> <html> <body>
<h1>Input Radio autofocus property</h1>
<form> RADIO: <input type="radio" id="rad1" name="BTN" autofocus> </form>
<br><br>
<button type="button" onclick="FocusVal()">KIỂM TRA FOCUS</button>
<p id="Sample"></p>
<script>
function FocusVal() {
var R = document.getElementById("rad1").autofocus;
document.getElementById("Sample").innerHTML = "Radio button autofocus = " + R;
}
</script> </body> </html>
Kết quả
Radio button có thuộc tính autofocus:

Sau khi nhấn nút, hiển thị true:
