简体   繁体   English

jquery-selected插件 - 在所选项目上显示“X”

[英]jquery-chosen plugin - display 'X' on selected item

I am using the jquery-chosen plugin. 我正在使用jquery选择的插件。 It is a multiple selection ListBox. 它是一个多选ListBox。 It is working fine. 它工作正常。 But I would like the selected items to have an 'X' beside the item so the user can delete it if they want to. 但我希望所选项目在项目旁边有一个“X”,以便用户可以删除它。 The default action is to backspace. 默认操作是退格。 What Attribute includes the 'X' on each selected item? 什么属性包含每个所选项目的“X”? This is my jquery code: 这是我的jquery代码:

<script type="text/javascript">
     $(document).ready(function () {
         $(".chosen-select").chosen({
             search_contains: true,
             no_results_text: "Sorry, no match!",
             single_backstroke_delete: false,
             allow_single_deselect: true
         });
         $('.chosen-container').css('width', '600px');
    });

This is my ListBox code: 这是我的ListBox代码:

 <asp:ListBox ID="lstBoxTo" runat="server" SelectionMode="Multiple"
                    data-placeholder="Choose recipient(s)…" class="chosen-select">                       
        </asp:ListBox>

Currently, I am using the attribute, 'single-backstroke-delete' but I would like to have an 'X' beside the selected value instead. 目前,我正在使用'single-backstroke-delete'属性,但我希望在所选值旁边有一个'X'。 How do you configure that? 你是如何配置的?

THanks. 谢谢。

UPDATE I believe my problem is the .png file needs to be added, 'chosen-sprite.png' to the project. 更新我相信我的问题是需要将.png文件添加到项目中的“selected-sprite.png”。 The chosen.css references it. selected.css引用它。 I added it to my Images folder and changed all of the paths to 'Image/chosen-sprite.png' but it still does not work. 我将它添加到我的Images文件夹并将所有路径更改为'Image / selected-sprite.png',但它仍然无效。
THere is a comment at the top of the .css file not to 'hand edit the file'. 这是.css文件顶部的注释,不要“手动编辑文件”。 Does anyone know how to add the image file to the project so it can see it? 有谁知道如何将图像文件添加到项目中,以便它可以看到它?

我将selected-sprite.png添加到了具有chosen.css文件的文件夹中,并且工作正常。

Reading the documentation here , it looks as if you need to add the multiple attribute to your asp:ListBox . 这里阅读文档,看起来好像需要将multiple属性添加到asp:ListBox

 <asp:ListBox ID="lstBoxTo" runat="server" SelectionMode="Multiple"         
    multiple data-placeholder="Choose recipient(s)…" 
    class="chosen-select">                       
 </asp:ListBox>

If ASP.Net objects to having an attribute ( multiple ) with no value, you could try multiple="true" and see if that works. 如果ASP.Net反对具有没有值的属性( multiple ),则可以尝试multiple="true"并查看是否有效。

Disclaimer: this is all from reading the documentation. 免责声明:这一切都来自阅读文档。 I have not tried this myself. 我自己没试过。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM