我有以下功能:
$(function () {
$(".techdropdown").change(function () {
var recordToUpdate = $(this).attr("id");
var selectedTech = $(".techdropdown").val();
window.alert(selectedTech);
$.post("/CalloutAdmin/UpdateTech?tech=" + selectedTech + "&id=" + recordToUpdate, function () { document.location = "/CalloutAdmin/Index/"; });
});
});
下拉列表如下:
@foreach (var item in Model)
{
@Html.DropDownList("TechnicianId", null, String.Empty, new { id = item.CalloutId, @class = "techdropdown" })
}
现在奇怪的是,JQuery 检测到 value 属性并使用 foreach 循环创建的 FIRST 下拉列表显示它(selectedTech),但其他下拉列表之后似乎没有发送 value 属性。
我在运行时检查过,选择选项肯定具有正确的值属性,但 JQuery 只是看不到它们。有任何想法吗?
更新
这是包含我的下拉列表的表格的 HTML:
<table class="table table-hover" style="background-color: white; width: 100%;">
<tr style="background-color: #e6e6e6;">
<th>
Client Name
</th>
<th style="text-align: center">
Technician Name
</th>
<th>
Date/Time Logged
</th>
<th>
Job Status
</th>
<th>
Technician Status
</th>
<th></th>
</tr>
<tr>
<td>
Michael Barnett
</td>
<td style="text-align: center">
Craig
<select class="techdropdown" id="7" name="TechnicianId"><option value="">Choose technician...</option>
<option value="1">Mike</option>
<option value="2">Craig</option>
</select>
</td>
<td>
2013/08/07 01:27:50 AM
</td>
<td>
</td>
<td>
ASSIGNED
</td>
<td>
<a href="/CalloutAdmin/Edit/7">Edit</a> |
<a href="/CalloutAdmin/Details/7">Details</a> |
<a href="/CalloutAdmin/Delete/7">Delete</a>
</td>
</tr>
<tr>
<td>
Michael Barnett
</td>
<td style="text-align: center">
<select class="techdropdown" id="8" name="TechnicianId"><option value="">Choose technician...</option>
<option value="1">Mike</option>
<option value="2">Craig</option>
</select>
</td>
<td>
2013/08/07 01:28:19 AM
</td>
<td>
</td>
<td>
UNASSIGNED
</td>
<td>
<a href="/CalloutAdmin/Edit/8">Edit</a> |
<a href="/CalloutAdmin/Details/8">Details</a> |
<a href="/CalloutAdmin/Delete/8">Delete</a>
</td>
</tr>
</table>