在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函数中调用JavaScript方法检查下拉列表的状态