引导选择不起作用 [英] Bootstrap-select not working

查看:41
本文介绍了引导选择不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 bootstrap 2.3.2 并希望实现元素看起来像下拉菜单.github里有解决办法:https://github.com/silviomoreto/bootstrap-select

I'm using bootstrap 2.3.2 and want to implement element to look like dropdown-menu. There is a solution in github: https://github.com/silviomoreto/bootstrap-select

我的代码:

<select class="selectpicker">
    <option>1</option>
    <option>2</option>
</select>

<script type="text/javascript">
    $( function() {
       $('.selectpicker').selectpicker();
    })
</script>

它不起作用.但是当我输入

It doesn't work. But when i type

$('.selectpicker').selectpicker();

在 Chrome DevTools 的控制台中 - 选择对下拉菜单的更改,它就可以工作了.

in console in Chrome DevTools - select changes to dropdown and it works.

推荐答案

需要在DOM准备好后调用初始化函数.这通常作为 $(document).ready() 功能块的一部分完成.

You need to call the initialising function after the DOM is ready. This is usually done as part of a $(document).ready() function block.

$(document).ready(function() {
   $('.selectpicker').selectpicker();
});

当您通过控制台尝试执行命令时,DOM 已经加载并可用.因此,呼叫有效.上面的代码示例应该类似.

When you are attempting the command via the console, the DOM is already loaded and available. As such the call works. The above code sample should work similarly.

这篇关于引导选择不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆