[英]Uncaught TypeError: $(…).selectBox is not a function
I'm using the code below to select options from drop down, but I'm getting: 我正在使用下面的代码从下拉菜单中选择选项,但是我得到了:
Uncaught TypeError: $(...).selectBox is not a function.
in console. 在控制台中。 I'm going to use jquery-selectBox . 我将使用jquery-selectBox 。
My code: 我的代码:
<script>
$(document).ready(function() {
$("SELECT").selectBox();
$("SELECT").selectBox('settings', {
'menuTransition': 'fade',
'menuSpeed': 'fast'
});
});
</script>
and in the body tag I get a select field: 在body标签中,我得到一个选择字段:
<select class="selectBox">
<option value="0">Login Type</option>
<option value="1">Admin</option>
<option value="2">Customer</option>
</select>
I included all JavaScript sources in my code, but still it's giving me the error. 我在代码中包含了所有JavaScript源,但仍然给我错误。 Any solution? 有什么办法吗?
In order to use jQuery selectBox , just load it properly on your page (eg via CDN ). 为了使用jQuery selectBox ,只需将其正确加载到页面上即可(例如, 通过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>
To use your markup more efficiently, in this case, use your element's class
attribute and its value selectBox
to select it using jQuery, eg: 为了更有效地使用标记,在这种情况下,请使用元素的class
属性及其值selectBox
通过jQuery选择它,例如:
Your markup: 您的标记:
<select class="selectBox">
Select it via: 通过以下方式选择它:
$(".selectBox").selectBox();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.