gpt4 book ai didi

javascript - 未捕获的 TypeError : $(. ..).selectBox 不是函数

转载 作者:行者123 更新时间:2023-12-03 01:34:57 27 4
gpt4 key购买 nike

我使用下面的代码从下拉列表中选择选项,但我得到:

Uncaught TypeError: $(...).selectBox is not a function.

在控制台中。我将使用jquery-selectBox .

我的代码:

<script>
$(document).ready(function() {
$("SELECT").selectBox();
$("SELECT").selectBox('settings', {
'menuTransition': 'fade',
'menuSpeed': 'fast'
});
});
</script>

在正文标记中我得到一个选择字段:

<select class="selectBox">
<option value="0">Login Type</option>
<option value="1">Admin</option>
<option value="2">Customer</option>
</select>

我在代码中包含了所有 JavaScript 源代码,但仍然出现错误。有什么解决办法吗?

最佳答案

为了使用jQuery selectBox ,只需将其正确加载到您的页面上即可(例如 via CDN )。

$(document).ready(function() {
$("select").selectBox();
$("select").selectBox('settings', {
'menuTransition': 'fade',
'menuSpeed': 'fast'
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.selectbox/1.2.0/jquery.selectBox.js"></script>

<select class="selectBox">
<option value="0">Login Type</option>
<option value="1">Admin</option>
<option value="2">Customer</option>
</select>

注意

为了更有效地使用标记,在本例中,请使用元素的 class 属性及其值 selectBox 来使用 jQuery 选择它,例如:

您的标记:

<select class="selectBox">

通过以下方式选择:

$(".selectBox").selectBox();

关于javascript - 未捕获的 TypeError : $(. ..).selectBox 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51113239/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com