我有 Bootstrap 下拉按钮,我想在用户单击此下拉按钮时获取数据,而不是在页面加载时需要加载国家/地区列表,这是我的代码;
<div class="btn-group">
<input class="text-box single-line" data-val="true" data-val-required="The Country field is required." id="Country" name="Country" type="text" value="US" />
<a class="btn dropdown-toggle country" id="country" data-toggle="dropdown">
<span class="caret"></span>
</a>
<ul class="dropdown-menu countrys" role="menu" aria-labelledby="dropdownMenu">
//store country list
</ul>
</div>
我单击下拉按钮,它无法触发 jquery 工作,似乎 Bootstrap 不允许自定义下拉功能。
$(document).ready(function () {
$('#country').click(function () {
// Only call notifications when opening the dropdown
if (!$(this).hasClass('open')) {
$.ajax({
type: "GET",
url: "/getCountries",
async: false,
dataType: "script"
});
}
});
});