HTMLInputElement: thuộc tính name
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Thuộc tính name của giao diện HTMLInputElement cho biết tên của phần tử <input>. Nó phản ánh thuộc tính name của phần tử.
Giá trị
Một chuỗi đại diện cho tên của phần tử.
Ví dụ
Cho đoạn HTML sau:
html
<p>
<label for="planet">Bạn được sinh ra trên hành tinh nào?</label>
<input id="planet" type="text" name="origin" />
</p>
Bạn có thể sử dụng thuộc tính name để lấy ra hoặc đặt tên của <input>:
js
const inputElement = document.querySelector("#planet");
console.log(`Tên của phần tử: ${inputElement.name}`); // "Tên của phần tử: origin"
inputElement.name = "planet"; // cập nhật tên của phần tử
Đặc tả kỹ thuật
| Specification |
|---|
| HTML> # dom-fe-name> |