gpt4 book ai didi

javascript - Selectpicker 无法处理下拉列表更改

转载 作者:行者123 更新时间:2023-11-28 06:15:20 24 4
gpt4 key购买 nike

我有两个下拉列表,一个用于国家/地区,另一个用于州。我希望状态根据国家/地区显示。我将 selectpicker 类添加到两个下拉列表中。但是当我在控制台中更改国家/地区时,它显示错误

错误

TypeError: $(...).selectpicker is not a function
return c.join(',');

我的代码

我的 HTML

 <select data-size="5" onchange="changeCountry(this.value)" class="form-control selectpicker bs-select-hidden" name="Tours[countryid]" id="Tours_countryid">
<option>Country1</option>
<option>Country2</option>
</select>

<select id="Tours_stateid" name="Tours[stateid]" data-size="5" class="form-control selectpicker bs-select-hidden" maxlength="50">
<option value="">---Select State---</option>
</select>

Javascript

<script src="bootstrap-select.js"></script>
$(document).ready(function()
{
$(".selectpicker").selectpicker();
});


function changeCountry(value)
{
$.ajax({
url: "<?php echo Yii::app()->createurl('/site/changecountry') ?>",
type: 'post',
data: {id: value},
success: function (result) {
$("#Tours_stateid").html(result)
$('.selectpicker').selectpicker('refresh');
}
});
}

最佳答案

在使用库“bootstrap-select.js”之前检查是否已加载:

<!DOCTYPE html>
<html>
<head>
...
<!-- Loading library -->
<script src="bootstrap-select.js"></script>

<!-- Using library -->
<script type="text/javascript">
$(document).ready(function()
{
$(".selectpicker").selectpicker();
});
</script>

</head>

<body>
<select data-size="5" onchange="changeCountry(this.value)" class="form-control selectpicker bs-select-hidden" name="Tours[countryid]" id="Tours_countryid">
<option>Country1</option>
<option>Country2</option>
</select>

<select id="Tours_stateid" name="Tours[stateid]" data-size="5" class="form-control selectpicker bs-select-hidden" maxlength="50">
<option value="">---Select State---</option>
</select>
</body>
</html>

关于javascript - Selectpicker 无法处理下拉列表更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36027946/

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