0

如何在 JavaScript 函数(jQuery)中访问“StudentID”值。

HTML:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<Student.Models.vwStudent>>" %>

    <div class="divClass">
      <table class="tableClass">
      <% foreach (var item in Model) { %>
        <tr class="trClass">
          <td class="tdClass">
            <%= Html.TextBox("StudentID") %>
          </td>
        </tr>
      <% } %>
      </table>
    </div>

查询:

 $('#ShowStudentID').click(function () {        
      $(".tdClass").each(function () {
          alert($(this).val());           
      });
 });

硕士(形式):

<% using(Html.BeginForm("SaveCommitment", "LPForm")) %>
<% { %>
<div>
<% Html.RenderPartial("DisplayStudents"); %>
</div>
<% } %>
<br/><br/>
<input type="button" id="ShowStudentID" name="ShowStudentID" value="Show StudentID" />
</div>

我曾尝试使用 text()、innerHTML() 和 innerText() 方法,但无法使其正常工作。任何帮助,将不胜感激。

提前致谢

4

2 回答 2

1

如果要获取 .tdClass 中输入的值,可以尝试以下操作:

 $('#ShowStudentID').click(function () {        
      $(".tdClass").find('input').each(function() {
          alert($(this).val());           
      });
 });
于 2012-07-23T21:14:50.240 回答
0

通过 ID 轻松快速地访问它:

$('#StudentID').val();
于 2015-12-22T14:55:39.370 回答