全国服务热线:4008-888-888

行业新闻

FORM表格中onclick()、submit()与onsubmit()的难题

近期碰到一次解决form数据信息的过虑,选用了button的onclick恶性事件来查验,发觉return false后表格依然递交了。 因此细心科学研究了下onclick、onsubmit、submit结合涵数中间的关联和差别 onsubmit: You can override this event by returning false in the event handler. Use

FORM表格中onclick()、submit()与onsubmit()的难题

 近期碰到一次解决form数据信息的过虑,选用了button的onclick恶性事件来查验,发觉return false后表格依然递交了。
因此细心科学研究了下onclick、onsubmit、submit结合涵数中间的关联和差别

  onsubmit:
You can override this event by returning false in the event handler.
Use this capability to validate data on the client side to prevent invalid data from being submitted to the server.
If the event handler is called by the onsubmit attribute of the form object,
the code must explicitly request the return value using the return function,
and the event handler must provide an explicit return value for each possible code path in the event handler function.
The submit method does not invoke the onsubmit event handler.
submit:
The submit method does not invoke the onsubmit event handler.
Call the onsubmit event handler directly.
When using Microsoft? Explorer 5.5 and later,
you can call the fireEvent method with a value of onsubmit in the sEvent parameter.
  form action= # method= POST name= A onsubmit= return X();
input type= text value= /
input quot;Y() type= submit value= 递交 /
/form
要是 onclick 未 return false 那麼就再次实行 onsubmit
要是 onsubmit 未return false 那麼表格就被递交出来了
此外一点书写上留意一定要 return X(); 才可以获得涵数的回到值,不然仅仅启用涵数,回到值未被传送
恰当书写:
input type=submit rdquo;return X();
//X() 回到false后,form的submit会被停止
不正确书写:
input type=submit rdquo;X()
//X() 回到false后未传送给onclick恶性事件,form的submit会再次

共享到:
文中"FORM表格中onclick()、submit()与onsubmit()的难题"由远航网站站长搜集梳理而成,仅作大伙儿学习培训与参照应用。大量网站建设实例教程尽在远航网站站长站。


在线客服

关闭

客户服务热线
4008-888-888


点击这里给我发消息 在线客服

点击这里给我发消息 在线客服