我有3个标签,这3个标签有常用的提交和取消按钮。当用户点击提交按钮时,它应该自动切换到验证已经触发的标签,如何通过以下代码实现此功能<登记/> 部分视图:Service.cs.html
<script type="text/javascript">
$(document.body).ready(function () {
getService("Test1");
});
function getService(serviceMenuId) {
if (serviceMenuId != undefined && serviceMenuId != '') {
jQuery("div#menubar li").each(function () {
var $li = jQuery(this);
$li.removeClass('sel');
});
document.getElementById(serviceMenuId).className = "sel";
}
$('div#Test1').hide();
$('div#Test2').hide();
$('div#Test3').hide();
$("div#" + serviceMenuId).show();
}
</script>
@using (Html.BeginForm())
{
<div id="Test1" style="position:relative">@{Html.RenderPartial("Test1", Model);}</div>
<div id="Test2" style="position:relative">@{Html.RenderPartial("Test2", Model);}</div>
<div id="Test3" style="position:relative">@{Html.RenderPartial("Test3", Model);}</div>
<div id="saveCancelButton" class="as-ext-form-button-div" style="margin-top: 20px;">
<button title="Click here to save" id="saveData" type="submit" onclick="return attributesValid();">Save</button>
</div>
}
答案 0 :(得分:0)
我不确定它会有所帮助,但您可能会尝试将重点放在无效数据上:
$("#saveData").click(function() {
if ($("form").valid())
{
alert("Valid!");
}
else
{
validator.focusInvalid();
}
return false;
});