【发布时间】:2019-03-12 20:30:42
【问题描述】:
我试图调用 java 脚本确认表单提交,但它跳过它。即使我想先运行 java 脚本进行确认,它也会直接调用控制器。 我不知道我做错了什么。 JV Scripts 还是新手。
HTML
@model WMS_Web.Models.FileMaintenance.PrincipalModels
@section Scripts {
@Scripts.Render("~/Script/FileMaintenance/CommonFunction.js")
}
@{
ViewBag.Title = "PrincipalModel";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Principal</h2>
@using (Html.BeginForm("Create","Principal",FormMethod.Post))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.CompanyId, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.CompanyId, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CompanyId, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<button onclick='functionConfirm("Do you like Football?", function yes() {
alert("Yes")
},
function no() {
alert("no")
});'>XXX</button>
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back", "ViewPrincipal")
</div>
Java 脚本
function functionConfirm(msg, myYes, myNo) {
var confirmBox = $("#confirm");
confirmBox.find(".message").text(msg);
confirmBox.find(".yes,.no").unbind().click(function () {
confirmBox.hide();
});
confirmBox.find(".yes").click(myYes);
confirmBox.find(".no").click(myNo);
confirmBox.show();
}
【问题讨论】:
-
什么是合资脚本?
-
<button/>会默认提交表单,建议改成<input type="button" />
标签: javascript c# html asp.net-mvc