ajax - Bootstrap 下拉项与 Ajax 源绑定(bind)

标签 ajax twitter-bootstrap dropdownbox

我有 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"
                });
            }
        });
    });

最佳答案

您可以尝试在下拉打开事件中添加ajax请求。像这样的东西:

$('#myDropdown').on('show.bs.dropdown', function () {
  // do something…
})

show.bs.dropdow——调用 show 实例方法时立即触发此事件。切换 anchor 元素可用作事件的 relatedTarget 属性。

关于ajax - Bootstrap 下拉项与 Ajax 源绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15436911/

相关文章:

python - Django 'TestForm' 对象没有属性 'fields'

jquery - 轨道上的 Ajax 4

ajax - Colfdfusion循环状态更新Ajax

twitter-bootstrap - 为什么我不使用多个 col 大小?

javascript - 如何获取DropDown中选中的数据ID?

javascript - 在 Select2 中显示多列

asp.net-mvc - 在 ASP.NET MVC 中使用 Fiddler 调试 AJAX

javascript - 如何在初始 vue.js/vue-router 加载时加载所有服务器端数据?

css - Twitter Bootstrap - 如何组合表单布局?

html - Bootstrap 导航栏文本/按钮位于页面的一半