选择2个多个标签和formatSelection

时间:2014-01-03 08:35:54

标签: jquery html

我正在使用jquery插件生成标签的select 2,现在我想让这些标签可以破解,但结果当我在选项中将选项formatSelection设置为href时它给了我类似的东西:Zleceniodawca

Html看起来像:

<select data-placeholder="Dane z kontraktu" class="select" multiple="multiple" tabindex="6" id="tags">
                    <option value=""></option>
                    <optgroup label="System">
                        <?php foreach($config_system as $input => $name) : ?>
                        <option value="<?php echo $input; ?>"><?php echo $name; ?></option>
                        <?php endforeach; ?>
                    </optgroup>
                    <optgroup label="Podstawowe">
                        <?php foreach($config_basic as $input => $name) : ?>
                        <option value="<?php echo $input; ?>"><?php echo $name; ?></option>
                        <?php endforeach; ?>
                    </optgroup>
                    <optgroup label="Sailing Schedule">
                        <?php foreach($config_ss as $input => $name) : ?>
                        <option value="<?php echo $input; ?>"><?php echo $name; ?></option>
                        <?php endforeach; ?>
                    </optgroup>
                </select>  

作为Jquery代码:

select: function()
{
    function formatSelection(item) {
        return '<a href="#">' + item.text + '</a>';
    }

    $('#tags').select2({
        formatSelection : formatSelection
    });
}

2 个答案:

答案 0 :(得分:1)

这就是诀窍:

 $('#tags').select2({
        formatSelection : formatSelection,
        escapeMarkup: function(m) { return m; }
    });

答案 1 :(得分:0)

你可以尝试在formatResult和formatSelection中添加事件,如下所示。

formatResult: formatSelection,
formatSelection: formatSelection,
相关问题