表单正确格式:
<form id="addForm" method="post">
<input type="text" name="username" placeholder="用户名" /> <input
type="password" name="password" placeholder="密码" /> <input
type="button" onclick="adduser()" value="新增" />
</form>
表单错误格式:
<form id="addForm" method="post">
<input type="text" name="username" placeholder="用户名" /> <input
type="password" name="password" placeholder="密码" /> <input
type="submit" onclick="adduser()" value="新增" />
</form>
本文对比了两种表单设计,一种为正确格式,使用按钮触发自定义函数;另一种为错误格式,将提交事件与自定义函数混淆。正确的表单设计应避免直接在提交按钮上绑定复杂操作,确保表单提交与业务逻辑分离。
189





