我有一个 Bootstrap 下拉列表
<button class="btn btn-primary" id="selectButton" data-toggle="dropdown">
Arrangement
<span class="caret"></span>
</button>
<ul class="dropdown-menu scrollable-menu" id="ulGenres">
@foreach (var item in Model.Tours)
{
<li>
<a href="#" data-pdsa-dropdown-val="@item.Id">@item.StringValue</a>
</li>
}
</ul>
我想要设置选定的项目
function DataLoad() {
var id = $("#TourId").val();
$("#Details").load('/umbraco/Surface/Tour/GetTourDetails?tourId=' + id);
}
$(document).ready(function () {
$("#ulGenres li a").on("click", function () {
// Get text from anchor tag
var id = $(this).data('pdsa-dropdown-val');
$("#TourId").val(id);
// Add text and caret to the Select button
var text = $(this).text();
$("#selectButton").html(text + ' <span class="caret"></span>');
// Put text into hidden field from model
$("#SelectedText").val(text);
DataLoad();
});
var id = $("#TourId").val();
$("#ulGenres li a").data("[pdsa-dropdown-val= " + id + "]").trigger("click");
//$("#ulGenres li:first-child a").trigger("click");
});
这并没有选择所需的正确元素。
$("#ulGenres li a").data("[pdsa-dropdown-val= " + id + "]")