2017-04-13 72 views
0

我有一個主視圖,其中有一個局部視圖。在我的部分觀點中,我有一個表格顯示了搜索結果。我想要的是當我點擊該行時,它應該提醒該行中的數據。但這沒有發生。javascript/jquery不能在局部視圖中工作。

我試圖在互聯網上幾乎一切,但沒有找到任何東西。

局部視圖:

@model List 
<string> 
<table class="table table-striped" id="tblGrid"> 
    <thead id="tblHead"> 
     <tr> 
     <th>Name</th> 
     <th>Email</th> 
     </tr> 
    </thead> 
    <tbody> 
     @for (int item = 0; item < Model.Count; item = item + 2) 
     { 
     <tr> 
     <td style="width: 300px"> 
      @Model[item].ToString() 
     </td> 
     @{ int temp = item; 
     item = item + 1; 
     } 
     <td style="width: 100px"> 
      @Model[item].ToString() 
     </td> 
     @{ 
     item = temp; 
     } 
     </tr> 
     } 
    </tbody> 
</table> 

數據被填充得很好,但JavaScript的不叫。

主:

<head> 
    <script type="text/javascript"> 
     $(document).ready(function() { 
     $("#tblGrid tr").live(function() { 
     $(this).addClass('selected').siblings().removeClass('selected'); 
     var value = $(this).find('td:first').html(); 
     alert(value); 
     });    
     }); 
    </script> 
</head> 
<body> 
    <input id="searchAttr" name="searchAttr" /> 
    <button href="#myModal" id="openBtn" data-toggle="modal" class="btn btn-default">Search</button> 
    <div id="searchresults"> 
    </div> 
</body> 

提供任何幫助,將不勝感激。

+0

你得到在瀏覽器的控制檯中的任何錯誤?你是否使用了足夠舊的jQuery版本,而'.live()'仍然被支持? – nnnnnn

+0

試着將你的''收盤前''標籤。另外,還要確保你調用你的''

0

你想使用jQuery沒有與它連接你的看法?

加入的頂部您的主這個

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script> 
+0

嗨,謝謝,但它沒有工作 –

+0

局部視圖支持javascript ??? –

相關問題