2014-03-06 36 views
0

我有在javascript函數我想parmID這是動態生成的動態創建表結構通過迭代泛型集合使用jQuery或JavaScript

<div> 
     @if (Model.parameterListForReviewerOne != null) 
     { 
      foreach (var item in Model.parameterListForReviewerOne) 
      { 
       if (item.parmID != null && item.parmID != 0) 
       { 
      <tr class="highlightRed parameterOfReviewer1 bluebgtable-confi"> 
       <td style="display: none">@Html.HiddenFor(modelItem => item.parmID) 
       </td> 
       <td align="center" width="25%"> 
        @Html.DisplayFor(modelItem => item.ParameterDesc, new { @readonly = "readonly" }) 
       </td> 
       <td align="center" class="one" width="35%"> 
        @*@Html.TextBoxFor(modelItem => item.Reviewer1Ratings, new { @class = "ReviewerOneClass", @id = "Ratings1_" + @item.parmID })*@ 
        @Html.DropDownListFor(model => item.Reviewer1Ratings, new SelectList(Model.RatingsList, item.Reviewer1Ratings), new { @class = "ReviewerOneClass HideinPrint", @id = "Ratings1_" + @item.parmID }) 
        <span class="ShowinPrint" id="[email protected]">dummy</span> <span style="color: #E80C4D; display: none;" class="hide" id="[email protected]"> 
         Invalid range.</span> <span style="color: #E80C4D; display: none;" class="hide" id="[email protected]"> 
          Required</span> 
       </td> 
       <td align="center" class="one" height="80px" width="40%"> 
        @Html.TextAreaFor(modelItem => item.Reviewer1Comments, new { @class = "ReviewerCommentsClass requiredField disableReviewer1 reviewer1ParaFieldLimit HideinPrint", @id = "Comments1_" + @item.parmID }) 
        <div class="ShowinPrint" id="[email protected]"> 
         dummy</div> 
        <span style="color: #E80C4D; display: none;" class="hide [email protected]" id="[email protected]"> 
         Required</span> <span id="[email protected]" class="classSec3FieldLimit" style="display: none"> 
         </span> 
       </td> 
      </tr> 
       } 
      } 
     } 
     <tr class="bluebgtable-confi"> 
      <td align="center" width="25%"> 
       Overall Ratings 
      </td> 
      <td align="center" id="OverallRating1" valign="middle" height="60px" width="35%"> 
       @* @Html.TextBoxFor(model => model.Reviewer1OverallRating)*@ 
       @Html.DropDownListFor(model => model.Reviewer1OverallRating, new SelectList(Model.RatingsList), new { @class = "HideinPrint" }) 
       <span class="ShowinPrint" id="forPrintReviewer1OverallRating">dummy</span> <span 
        style="color: #E80C4D; display: none;" class="hide" id="span_OverAllRatingReviewer1"> 
        Invalid range.</span> <span style="color: #E80C4D; display: none;" class="hide" id="span_OverAllRatingReviewer1Required"> 
         Required</span> 
      </td> 
      <td id="OverallRating1" align="center" class="requiredField" height="80px" width="40%">@Html.TextAreaFor(model => model.Reviewer1OverallRatingComments, new { @class = "disableReviewer1 HideinPrint" }) 
       <div class="ShowinPrint" id="forPrintReviewer1OverallRatingComments"> 
        dummy</div> 
       <p>@Html.ValidationMessageFor(model => model.Reviewer1OverallRatingComments)</p> 
       <span style="color: #E80C4D; display: none;" class="hide hideOverallRating1" id="span_Reviewer1OverallRatingCommentsRequired"> 
        Required</span> 
      </td> 
     </tr> 
    </div> 

視圖我怎樣才能parmID在JavaScript或jquery.actually我想複製代碼到div將隱藏我想要獲得動態生成的ID。

+0

這是ASP.NET? –

回答

0

在MVC4中,您可以編寫<tr id="@Html.IdFor(modelItem => item.parmID)" ...,然後用jquery選擇這些ID。 或產生的TR <tr class='myclass'>一些JavaScript即

<script> 
var id = '@Html.IdFor(modelItem => item.parmID)'; 
</script> 

或設置屬性或類,只需使用$('.myclass').forEach(...)

0

首先編輯tr存儲其parmID。像:

<tr data-parmID="@item.parmID" class="highlightRed parameterOfReviewer1 bluebgtable-confi"> 
. 
. 
. 
</tr> 

後,您可以遍歷他們

$("tr").each(function() { 
    var parmID = $(this).attr("data-parmID"); 
    // do your work here 
});