简体   繁体   English

jQuery-UI可以选择输入

[英]jQuery-UI selectable into input

please follow this link: FIDDLE 请点击以下链接: FIDDLE

I'm building this input (that is a search tool) and I'm putting some "tips" to select. 我正在构建此输入(这是一个搜索工具),并添加了一些“提示”以供选择。

I use an hidden paragraph to store it better. 我使用一个隐藏的段落来更好地存储它。

I have 2 problems: 我有2个问题:

  1. if you try to select 3 tips and that to deselect all you can see that the hidden text is empty but the input have the last tips selected. 如果您尝试选择3个提示,然后取消选择所有提示,则可以看到隐藏的文本为空,但是输入中最后一个提示被选中。
  2. I would like that if I manually type "Hello world" and than I use tips, Hello world stay there always, also if I remove all the tips than. 我想如果我手动键入“ Hello world”,然后使用提示,那么Hello world会一直存在,并且如果我删除所有提示也不会。

Thank you in advance for your help. 预先感谢您的帮助。

for your first question, try this code 对于第一个问题,请尝试以下代码

$(document).ready(function() {
    var lista = $('ul#common-list');
    lista.bind("mousedown", function (e) {
        e.metaKey = true;
    }).selectable({
        stop: function () {
            var result = $("input#search");
            var fakeText = $('p.hidden-tips-text').empty();
            $(".ui-selected", this).each(function () {
                var index = $(this).text();
                fakeText.append((index) + " ");
            });
           result.val(fakeText.text());
        }
    });
});

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

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