---
url: /docs/guide/usage/linter/rules/react/button-has-type.md
---

### 作用

对所有 HTML `button` 元素强制显式指定 `type` 属性。

### 为什么这不好？

`button` HTML 元素的 `type` 属性默认值是
`"submit"`，这通常不是期望的行为，并且可能导致
意外的页面重新加载。

### 示例

以下是此规则的**错误**代码示例：

```jsx
<button />
<button type="foo" />
```

以下是此规则的**正确**代码示例：

```jsx
<button type="button" />
<button type="submit" />
```

## 配置

此规则接受一个包含以下属性的配置对象：

### button

类型: `boolean`

默认值: `true`

如果为 true，则允许 `type="button"`。

### reset

类型: `boolean`

默认值: `true`

如果为 true，则允许 `type="reset"`。

### submit

类型: `boolean`

默认值: `true`

如果为 true，则允许 `type="submit"`。

## How to Use

## 版本

此规则在 v0.1.1 中添加。

## 参考
