Select2:如何添加链接而不是“未找到结果"文本? [英] Select2: how to add a link instead of "No results found" text?

查看:88
本文介绍了Select2:如何添加链接而不是“未找到结果"文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的代码:

$('#cow_id_2').select2({
        allowClear: true,
        placeholder: "Search a cow/dam ID",
        formatNoMatches: function (term) {
            return "<a href=/'http://google.com/'>Add</a>";
        }
    });

当我尝试添加链接时,插件将停止工作. 我正在使用Select2 4.0.3版本

When I try to add a link the plugin just stop working. I am using Select2 4.0.3 version

推荐答案

如果您使用的是版本2或更高版本的select2,请尝试以下操作:

If you're using version 4 or newer of select2, try this:

$('#cow_id_2').select2({
        allowClear: true,
        escapeMarkup: function (markup) { return markup; },
        placeholder: "Search a cow/dam ID",
        language: {
            noResults: function () {
                 return "<a href=/'http://google.com/'>Add</a>";
            }
        }
    });

这篇关于Select2:如何添加链接而不是“未找到结果"文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆