2017-09-13 77 views
0

我在ASP MVC部分类是这样工作的:隐藏按钮不会使用jQuery

<div class="table-responsive"> 
    <table class="table" id="tbl_visitors" data-animate="fadeInRight"> 
    <thead> 
     <tr> 
     <th> 
      @Html.DisplayNameFor(model => model.VisitorId) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.FirstName) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.LastName) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.TicketId) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.RequestStatus) 
     </th> 
     <th></th> 
     <th></th> 
     </tr> 
    </thead> 
    <tbody> 
     @foreach (var item in Model) { 
     <tr> 
     <td> 
      @Html.DisplayFor(modelItem => item.VisitorId) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.FirstName) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.LastName) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.TicketId) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.RequestStatus) 
     </td> 
     <td id="item_checkbox"> 
      @if (item.RequestStatus != "Pending") { 
      <input [email protected] checked="checked" class="use-this switch-toggle switch-flat-mini switch-toggle-flat" type="checkbox"> 
      <label [email protected]></label> 
      } else { 
      <input [email protected] class="use-this switch-toggle switch-flat-mini switch-toggle-flat" type="checkbox"> 
      <label [email protected]></label> 
      } 
     </td> 
     <th> 
      <a href="javascript:void(0);" onclick="deletevisitor(@item.VisitorId, @item.TicketId) ">Remove</a> 
     </th> 
     </tr> 
     } 
    </tbody> 
    </table> 
</div> 
<div class="alignright" id="div_btn_approve"> 
    <button id="btn_approve_ticket" class="button button-border button-rounded button-green">Approve</button> 
</div> 

和脚本来禁用我的“指数”的观点在局部视图按钮,如下所示:

function getVisitorsOfApprovedTicket(ticketId, requestedBy, schedule) { 
    var url = '/Member/GetVisitorViaTicketId?ticketId=' + ticketId; 
    $("#div_approved_ticket_visitors").load(url); 
    $("#hidden_created_by").val(requestedBy); 
    //$("#btn_approve_ticket").prop("disabled", true); 
    $("#btn_approve_ticket").hide(); 
} 

当我尝试通过创建脚本来把它藏在我的局部视图,它隐藏的按钮,但为何它没有在我的索引视图工作时,我称之为局部视图?你能告诉我怎么做对吗?谢谢。

+0

你在哪里调用这个函数? – madalinivascu

+0

在我的索引视图中,放置了我需要隐藏的按钮的部分视图。 – Ibanez1700

+0

何时何地调用getVisitorsOfApprovedTicket()方法? –

回答

2

因为.load还没有结束,如果尝试.hide()不存在的元素:

function getVisitorsOfApprovedTicket(ticketId, requestedBy, schedule) { 
    var url = '/Member/GetVisitorViaTicketId?ticketId=' + ticketId; 
    // this is a async process 
    $("#div_approved_ticket_visitors").load(url); 
    $("#hidden_created_by").val(requestedBy); 
    //$("#btn_approve_ticket").prop("disabled", true); 
    // you are trying to hide an element that is not present yet. 
    $("#btn_approve_ticket").hide(); 
} 

如果你想隐藏这是var url = '/Member/GetVisitorViaTicketId?ticketId=' + ticketId;视图中的元素。你需要等待它继续之前先加载:

function getVisitorsOfApprovedTicket(ticketId, requestedBy, schedule) { 
    var url = '/Member/GetVisitorViaTicketId?ticketId=' + ticketId; 
    // this is a async process 
    $("#div_approved_ticket_visitors").load(url, function() { 
    // this function is called after its done 
    // here you can safely hide the element 
    $("#btn_approve_ticket").hide(); 
    }); 
    $("#hidden_created_by").val(requestedBy); 
    //$("#btn_approve_ticket").prop("disabled", true); 
} 

希望帮助