---
title: "form中属性跟input名冲突解决"
author: "foolraty"
date: "2010-04-27T16:29:22Z"
tags: []
categories: ["Web前端"]
slug: "form-input"
draft: false
lastmod: "2010-04-27T16:29:22Z"
id: 654287
url: "https://foolraty.iteye.com/blog/654287"
---

```java
<form action="http://www.163.com/" method="get">
<input type="text" name="action" value="http://www.sohu.com/" />
<button onclick="subm(this.form)">submit</button>
</form>
<script type="text/javascript">
function subm(o){
        o.attributes['action'].value = o.elements['action'].value;
        o.submit();
}
</script>
```

出现这种情况，很可能是因为 form 的 elements 里面有一个名为 action，
导致form.action出现冲突，因此在使用表单元素名称的时候，
尽量避免使用 submit reset action method name等作为elements的名称
一般情况下是不会出现问题，但是如果你需要用js去修改某个属性(如action method name等)，
或者触发某个事件（如submit reset等）的时候，可能会出现这些冲突