我为html div修改调用了ajax函数,在div修改内容中有'select2‘jquery类的选择框。在ajax加载select2 jquery插件后,它就不能正常工作了。
这是我的js:
$('body').on('click', '.portlet > a.reloadcontent', function(e) {
$.ajax({
type: "GET",
cache: false,
url: url,
dataType: "html",
success: function(res) {
$('#colpart').find('.portlet-body').html(res);
}
});
});
这是我的HTML:
<div id="#colpart">
<a href="#" data-url="columnspage.html" class="reloadcontent" data-load="true">Columns</a>
<div class="portlet-body"></div>
</div>
columnspage.html
<select class="form-control select2me" data-placeholder="">
<option value=""></option>
<option value="1">Column 1</option>
</select>
select2 jquery插件的select2me类。
发布于 2015-02-23 20:52:38
您需要在成功回调后初始化select,因为您的下拉列表是动态添加到DOM中,
success:function(res){
$('#colpart').find('.portlet-body').html(res);
// reinit your plugin something like the below code.
$('.select2me').select2();
}
发布于 2018-07-25 05:38:12
在ajax成功函数中,您需要初始化select。
示例:
success: function (html) {
// your code here
$(".select2").select2(); // init the select
}
https://stackoverflow.com/questions/28674228
复制相似问题