submit()方法是jQuery中的一个内置方法,用于提交事件或在提交事件发生时附加要运行的函数。此方法只能应用于表单元素。 语法:
null
$(selector).submit(parameters);
参数: 此方法的参数是可选的。
返回值: 此方法返回所选元素以及附加的事件。
项目1: 显示submit()方法工作的jQuery代码
< html > < head > < script src = </ script > < script > // jQuery code to show the working of this method $(document).ready(function() { $("form").submit(function() { alert("Form submitted Successfully"); }); }); </ script > < style > .gfg { font-size:40px; color:green; font-weight:bold; text-align:center; } .geeks { font-size:17px; text-align:center; margin-bottom:20px; } </ style > </ head > < body > < div class = "gfg" >GeeksforGeeks</ div > < div class = "geeks" >A computer science portal for geeks</ div > < form action = "" > < table border = 1 align = "center" > < tr > <!-- Enter Username --> < td >Username:</ td > < td >< input type = text name = name size = 25 </td> </ tr > < tr > <!-- Enter Password. --> < td >Password:</ td > < td >< input type = password name = password1 size = 25 </td> </ tr > < tr > <!-- To Confirm Password. --> < td >Confirm Password:</ td > < td >< input type = password name = password2 size = 25 ></ td > </ tr > < tr > < td colspan = 2 align = right > < input type = submit value = "Submit" ></ td > </ tr > </ table > </ form > </ body > </ html > |
输出:
项目2:
< html > < head > < script src = </ script > < script > // jQuery code to show the working of this method $(document).ready(function() { $("form").submit(function() { alert("Form submitted Successfully"); }); $("button").click(function() { $("form").submit(); }); }); </ script > < style > .gfg { font-size:40px; color:green; font-weight:bold; text-align:center; } .geeks { font-size:17px; text-align:center; margin-bottom:20px; } </ style > </ head > < body > < div class = "gfg" >GeeksforGeeks</ div > < div class = "geeks" >A computer science portal for geeks</ div > < form action = "" > < table border = 1 align = "center" > < tr > <!-- Enter Username --> < td >Username:</ td > < td >< input type = text name = name size = 25 </td> </ tr > < tr > <!-- Enter Password. --> < td >Password:</ td > < td >< input type = password name = password1 size = 25 </td> </ tr > < tr > <!-- To Confirm Password. --> < td >Confirm Password:</ td > < td >< input type = password name = password2 size = 25 ></ td > </ tr > < tr > < td colspan = 2 align = right > < button >Click me !</ button > </ tr > </ table > </ form > </ body > </ html > |
输出:
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END