HTML DOM Input Text name 属性
htmlweb developmentfront end technology更新于 2024/5/28 4:28:17
HTML DOM Input Text name 属性用于设置或返回输入文本字段的 name 属性。name 属性有助于在表单数据提交到服务器后对其进行识别。
语法
以下是语法 −
设置 name 属性 −
textObject.name = name
此处,name 用于指定文本字段的名称。
示例
让我们来看一个文本 name 属性的示例 −
<!DOCTYPE html>
<html>
<body>
<h1>Input Text name Property</h1>
USERNAME: <input type="text" id="USR" name="user_name">
<p>Change the name of the text field by clicking the below button</p>
<button onclick="changeName()">CHANGE NAME</button>
<p id="Sample"></p>
<script>
function changeName() {
document.getElementById("USR").name ="NEW_USER" ;
document.getElementById("Sample").innerHTML = "Text field name is now NEW_USER";
}
</script>
</body>
</html>
输出
这将产生以下输出。由于我们已将 maxLength 设置为 5,因此仅允许 5 个字符 −

点击"更改姓名"按钮 −

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

