2013-10-02 80 views
0

我有3個標籤,這3個標籤有共同的提交和取消按鈕。當用戶點擊提交按鈕時,它應該自動切換到驗證已經觸發的標籤,我該如何實現此功能與下面的代碼
管窺:Service.cs.html關於在MVC中的標籤驗證

<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>&nbsp;&nbsp; 

    </div> 
} 

回答

0

我不知道它會幫助,但你可能嘗試在無效數據使用聚焦:

$("#saveData").click(function() { 
     if ($("form").valid()) 
{ 
       alert("Valid!"); 
} 
     else 
{ 
       validator.focusInvalid(); 
} 

     return false; 
    });