2016-01-12 168 views
0

我有下面的代碼,它有按鈕和click它應該顯示hidden窗體。但它不,爲什麼?爲什麼隱藏窗體不顯示?

@model EmployeesTest.Models.EmployeeVM 

@{ 
    ViewBag.Title = "Create"; 
} 

<h2>Create</h2> 

<input type="submit" name="name" value="New Entry" id="new"/> 

@using (Html.BeginForm()) { 
    <div id="frm" style="visibility:hidden"> 
    <table> 
    <thead> 
     <tr> 
      <td></td> 
      <td></td> 
      <td></td> 
     </tr> 
    </thead> 
    <tbody> 
     <tr> 
      <td>@Html.LabelFor(x=>x.emp.FirstName)</td> 
      <td>@Html.TextBoxFor(x=>x.emp.FirstName)</td> 
      <td>@Html.ValidationMessageFor(x => x.emp.FirstName)</td> 
     </tr> 
     <tr> 
      <td>@Html.LabelFor(x=>x.emp.LastName)</td> 
      <td>@Html.TextBoxFor(x=>x.emp.LastName)</td> 
      <td>@Html.ValidationMessageFor(x => x.emp.LastName)</td> 
     </tr> 
     <tr> 
      <td></td> 
      <td></td> 
      <td><input type="submit" value="Save"/></td> 
     </tr> 
    </tbody> 
</table> 
     </div> 
} 

@section Scripts { 
    @Scripts.Render("~/bundles/jqueryval") 

    <script> 
     $(document).ready(function() { 

      $('#new').click(function() { 
       (this).preventDefault(); 

       $('#frm').css('visibility', 'visible'); 

      }); 
     }); 
    </script> 
} 
+0

任何控制檯錯誤? –

+0

你能確認jQuery實際上正在加載嗎? –

+0

@RajeshJNair未捕獲TypeError:this.preventDefault不是函數 –

回答

1

刪除(this).preventDefault並通過event作爲參數,防止如下:

$(document).ready(function() { 
    $('#new').click(function (event) { 
      event.preventDefault(); 
      $('#frm').css('visibility', 'visible'); 
    }); 
}); 

Since the type of button is just button there is no need to prevent its default action.

+0

'event.preventDefault() ;'在這種情況下(它只是一個'type =「button」') –

+0

@StephenMuecke ..是的..提到它.. :) –

+0

Downvote ??????? –

1
$(document).ready(function() { 
    $('#new').click(function (e) { 
     e.preventDefault(); 
     $('#frm').css('visibility', ''); 
    }); 
}); 
相關問題