
(function($){ $.fn.Lform = { Lget:function(c){ var s = ""; if(!c){ $("body form").each(function(i, e) { s+= "<input type='button' class='cssform' data-lfm='" + i + "' value='" + i + "番目のフォームを送信させる'><br>"; }); }else{ s = "<input type='button' class='cssform' data-lfm='" + c + "' value='" + c + "番目のフォームを送信させる'><br>"; } return (function(s){ console.log(s); $("#lsform").html(s); $(".cssform").click(function(){ var i = $(this).data("lfm"); $("body form").eq(i).submit(); }); })(s); } }; })(jQuery);
<!DOCTYPE html> <html> <head> <title>JQプラグインか?::from送信プラグイン{BODYの中に複数のフォームが有る場合、指定したフォームを送信させる。}</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="lform.js"></script> <script> $(function(){ $("#gLform").click(function(){ $("#gLform").Lform.Lget(); }); $("#gLform1").click(function(){ $("#gLform1").Lform.Lget(1); }); }); </script> <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-71682075-1', 'auto'); ga('send', 'pageview'); </script> </head> <body> <h1>form送信プラグイン{BODYの中に複数のフォームが有る場合、指定したフォームを送信させる。}</h1> <input type="button" id="gLform" value="送信する"><input type="button" id="gLform1" value="送信する"> <p id="lsform"></p> <form action="https://yahoo.co.jp" method="GET"> </form> <form action="https://google.co.jp" method="GET"> </form> <form action="https://www.msn.com/ja-jp" method="GET"> </form> </body> </html>