ITeye博客

form中属性跟input名冲突解决

foolraty · 2010-04-27 16:29 · Web前端 · Markdown

<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等)的时候,可能会出现这些冲突

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。