form表单的action和onsubmit事件说明

原文地址: https://blog.csdn.net/hnczlzj/article/details/53618605

首先 action在form是属性,onsubmit是事件。

[html]  view plain  copy
  1. <code class="language-html"><form action="table1.jsp<span style="font-family:Arial, Helvetica, sans-serif;">onSubmit="return check();"> </span></code>  
  1. <div> <input type="text" id="in" value="helloWord"/>
  2. <input type="submit" value="提交" />
  3. </div>
  4. </form>
  1. function check(){
  2. var oText = document.getElementById("in").value;
  3. alert(oText);
  4. if(oText =="false"){
  5. return false;
  6. }
  7. else {
  8. return true;}
  9. }

要说执行的先后顺序,onSubmit在先,先验证,验证返回false时,则无法到达action="url"地址。如果是返回true或者没有返回值,则通过action转向url地址。 

也就是说onsubmit可以阻止action的提交

onSubmit="return check();" 这里的return是一定要写的。不可写成onsubmit=check();

猜你喜欢

转载自blog.csdn.net/justlpf/article/details/80985777