【问题标题】:Make button to fire Javascript only if @Html.EditorFor is equal to "Closed"仅当 @Html.EditorFor 等于“已关闭”时,才使按钮触发 Javascript
【发布时间】:2020-01-27 13:19:36
【问题描述】:

在 MVC Web 项目中,我在视图中有一个 保存按钮,单击时会调用 javascript 函数:

<input type="submit" value="Save" class="btn btn-default" name="action" onclick="Confirm()" />

只有在状态下拉菜单设置为选择“已关闭”时,我才能使此按钮调用 javascript 函数?

这是 javascript

function Confirm() {
var input = $("<input />");
input.attr("type", "hidden").attr("name", "confirm_value");
    if (confirm("Do you want to save the ticket to the knowledge base archive?")) {
        input.val("Yes");
    } 
    else {
        input.val("No");
    }
$("form")[0].appendChild(input[0]);
}

这是下拉列表的 HTML 代码:

@Html.LabelFor(model => model.vcStatus, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.DropDownListFor(m => m.vcStatus, Model.StatusList)
@Html.ValidationMessageFor(model => model.vcStatus, "", new { @class = "text-danger" }) </div>

非常感谢您的帮助。

【问题讨论】:

    标签: javascript jquery html model-view-controller


    【解决方案1】:

    您可以在保存按钮上调用 javascript 方法并在 javascript 函数中检查下拉菜单的状态

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-03-05
      • 2020-11-28
      • 1970-01-01
      • 2017-12-27
      • 2021-03-06
      • 2011-09-11
      • 2013-05-20
      相关资源
      最近更新 更多