简体   繁体   English

按钮提交前的Javascript函数

[英]Javascript function before button submit

I have to call a js function before asp-action is called on button click 在点击按钮之前调用asp-action之前,我必须调用一个js函数

<form asp-action="Index" method="post">
                @Html.AntiForgeryToken()
              var x = jsfunction();
                <div class="form-group">
                    <input type="submit" value=@Localizer["Button"] class="btn Button"  />
                </div>
            </form>

I want to call the js funtion on click of the submit button and then it should proceed to the controller action method 我想点击提交按钮调用js功能,然后它应继续执行控制器操作方法

You can try as follow : 您可以尝试如下:

<form id='myForm' asp-action="Index" method="post">
            @Html.AntiForgeryToken()
          var x = jsfunction();
            <div class="form-group">
                <input id='submitBTN' type="button" value=@Localizer["Button"] class="btn Button"  />
            </div>
        </form>

And call it's click event by jquery or js .. 并通过jquery或js调用它的click事件。

<script>
  $('#submitBTN').on('click', function () {
    jsfunction();
    $('#myForm').submit();
   }
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM