0
如果我有formatSelection
的標記,其中包含圖像並且select2-selecting
事件中有window.location.href
事件,則圖像將被破壞。如果我刪除window.location.href
,則圖像可以工作,並且可以在加載新頁面之前看到。格式圖像在將用戶發送到選擇事件的新頁面時,選擇標記被打破
$('.select2#topbarSearch').on("select2-selecting", function(e) {
window.location.href = 'www.example.com';
});
function selectionFormat(data) {
var markup = "<table class='search-result'><tr>";
if (data.image !== undefined) {
markup += "<td class='data-image'><img style='height: 25px;' src='" + data.image + "'/></td>";
}
markup += "<td class='data-info-selected'><div class='data-title'>" + data.title + "</div>";
markup += "</td></tr></table>";
return markup;
}