HTML button name 属性

htmlweb developmentfront end technology更新于 2025/8/23 6:04:17

<button> 元素的 name 属性用于设置按钮的名称。多个按钮可以具有相同的名称,但我们可以使用 name 属性从这些按钮提交不同的值。

以下是语法 −

<button name="btn_name">

上面,btn_name 是按钮的名称。现在让我们看一个在 <button> 元素中实现 name 属性的示例 −

示例

<!DOCTYPE html>
<html>
<body>
<form action="" method="get">
   Get the details of the employee:<br><br>
   <button name="details" type="submit" value="addr">Address</button>
   <button name="details" type="submit" value="ph">Phone</button>
   <button name="details" type="submit" value="appraisal">Appraisal %</button>
</form>
</body>
</html>

输出

在上面的例子中,即使按钮名称相同,例如将"details"设置为按钮名称,也会提交不同的值 −

<button name="details" type="submit" value="addr">Address</button>
<button name="details" type="submit" value="ph">Phone</button>
<button name="details" type="submit" value="appraisal">Appraisal %</button>

相关文章


有用资源