我有按钮和动态生成的下拉菜单。我想在页面加载时访问下拉的ID,但自动生成的ID只会给我第一个下拉的ID(请看脚本)。并请,如果你能告诉我如何缩进代码正确如何在asp.net mvc中获取自动生成的多个控件的id?
<div class="row">
<div class="col-md-9">
<div data-id="@data.id" id="[email protected]">
@foreach (var slot in data.avail_slots)
{
if (slot.day == "Monday"){
<div class="col-md-3 col-xs-4" style="line-height:2em;">
<button id="appointment_click" data-toggle="modal" data-target="#confirmation" style="margin-bottom:4px" class="pull-left btn btn-pill btn-primary">@slot.time</button>
</div>
}}
</div>
<div data-id="@data.id" id="[email protected]">
@foreach (var slot in data.avail_slots)
{if (slot.day == "Tuesday")
{<div class="col-md-3 col-xs-4" style="line-height:2em;">
<button id="appointment_click" data-toggle="modal"data-target="#confirmation" style="margin-bottom:4px" class="pull-left btn btn-pill btn-primary">@slot.time</button>
</div>
}
}
</div>
<div data-id="@data.id" id="[email protected]">
@foreach (var slot in data.avail_slots)
{if (slot.day == "Wednesday")
{
<div class="col-md-3 col-xs-4" style="line-height:2em;">
<button id="appointment_click" data-toggle="modal" data-target="#confirmation" style="margin-bottom:4px" class="pull-left btn btn-pill btn-primary">@slot.time</button>
</div>
}
}
</div>
<div data-id="@data.id" id="[email protected]">
@foreach (var slot in data.avail_slots){
if (slot.day == "Thursday"){
<div class="col-md-3 col-xs-4" style="line-height:2em;">
<button id="appointment_click" data-toggle="modal" data-target="#confirmation" style="margin-bottom:4px" class="pull-left btn btn-pill btn-primary">@slot.time</button></div>
}}
</div>
<div data-id="@data.id" id="[email protected]">
@foreach (var slot in data.avail_slots){
if (slot.day == "Friday"){
<div class="col-md-3 col-xs-4" style="line-height:2em;">
<button id="appointment_click" data-toggle="modal" data-target="#confirmation" style="margin-bottom:4px" class="pull-left btn btn-pill btn-primary">@slot.time</button>
</div>
}}
</div>
<div data-id="@data.id" id="[email protected]">
@foreach (var slot in data.avail_slots){
if (slot.day == "Saturday") {
<div class="col-md-3 col-xs-4" style="line-height:2em;">
<button id="appointment_click" data-toggle="modal" data-target="#confirmation" style="margin-bottom:4px" class="pull-left btn btn-pill btn-primary">@slot.time</button></div>
}
}
</div>
<div data-id="@data.id" id="[email protected]">
@foreach (var slot in data.avail_slots){
if (slot.day == "Sunday"){
<div class="col-md-3 col-xs-4" style="line-height:2em;">
<button id="appointment_click" data-toggle="modal" data-target="#confirmation" style="margin-bottom:4px" class="pull-left btn btn-pill btn-primary">@slot.time</button></div>}}
</div>
</div>
<div class="col-md-3">
<select data-id="@data.id" id="[email protected]" class="temp">
@foreach (var d in ad_list){
<option value="@d.id">@d.day_name</option>}
</select>
</div>
<script>
var today_number = new Date().getDay();
var today = get_all(today_number)
$('select>option:eq(' + today_number + ')').attr('selected', true);
var id = $('.temp').attr('data-id');
</script>
做所有下拉具有相同的ID? –
我正在使用数据ID给他们不同的ID。 我无法在网页加载时访问它 – Zawar