为什么一点onclick按钮就提交表单?

下面是一个表单,有一个onclick按钮,点击后上面文本框的内容被添加到下面的文本域中,并可以一直添加,然后点击submit后提交到另一个页面。但是,在Ie9或者火狐浏览器中我一点onclick为什么总是提交表单,在搜狗,360浏览器中并未出现这样的状况。想问是不是浏览器的兼容问题,该如何解决。

<form action="abc.jsp" method="get" >
    <input id = "input" size="30" maxlength="100"   />
    <button >add</button>
  </p>
  <p>
    <label for="textarea"></label>
    <textarea name="name" id="textarea" cols="40" rows="5" readonly="true"></textarea>    
    &nbsp;&nbsp;<input type="submit" id="button2" value="submit" />
    <input type="reset"  id="button" value="reset" />
  </p>
</form>

记住:
请始终为按钮规定 type 属性。Internet Explorer 的默认类型是 "button",而其他浏览器中(包括 W3C 规范)的默认值是 "submit"。

所以,你要做的很简单:
1、放弃使用button标签,改用input
2、使用button标签,但是指定其 type为 button.

可以参照:http://www.w3school.com.cn/tags/tag_button.asp


直接用<input type="button" />来处理吧

posted @ 2015-03-11 23:56  r3call  阅读(601)  评论(0编辑  收藏  举报