English 中文(简体)
如何在fcbkcomplete中选择价值时获得ids? - 增加支架
原标题:How to get ids when a value is selected in fcbkcomplete? - jsfiddle added

请穿下面的阴道。 我正试图在<代码>fcbkcomplete方框中拿到选定产品的标子,并在文本箱中以作为 com分离值。 我写了实现这一目的的职能,但却没有工作。 这一职能增加了第一个数值的id,没有吸收多个甄选箱中增加的其他价值。

http://jsfiddle.net/balac/xDtrZ/1/

我增加了<代码>json.txt。 本报告载有类似数据。

[{"key":"2", "value":"Canon Powershot "},{"key":"3", "value":"Fastrack Bag"},{"key":"4", "value":"Iphone 4 "},{"key":"5", "value":"Levis Jeans"},{"key":"7", "value":"Indig"},{"key":"8", "value":"Dashing Cars"},{"key":"9", "value":"dsdas"},{"key":"10", "value":"fsfs"}]

In the above json value key is the id which I want to display in the textbox as comma separated values. value is the value which will be coming in the dropdown for selection.

while selecting the values in the drop down i want the corresponding key to get added in the textbox as comma separated values.

问题是,在案文箱中,没有增加第一个项目的关键。

希望是具体的,并说得很详细。 如果有人想要澄清,请我作更多解释。

最佳回答

我认为,我为你找到了更简单的解决办法。 牢记,由于我在评论中提到的问题,我不得不大大简化你的<代码>fcbkcomplete。 使其发挥作用。

$(document).ready(function() {
    $("#select3").fcbkcomplete({
        addontab: true,
        maxitems: 10,
        input_min_size: 0,
        height: 10,
        select_all_text: "select",
        onselect: clicker
    });
});

var clicker = function() {
    var selected = new Array();

    $( option , this).each(function() {
        selected.push($(this).val());
    });

    $( #interest ).val(selected.join( ,  ));
};

See it in action here.

<>说明: 我不得不人工添加<代码><option> s至select list,以获得实际工作权利fcbkcomplete。 然而,我的逻辑应当毫无结果地为你们工作。

此外,fcbkcomplete 显然动态地改变了<option> sid to some such as opt_vaQDzJU37ArScs818rc8HUwz9gm1wyp,因此我不得不使用这一数值。 如果你重新确定使用补贴而不是价值,就会有工作关系。

为了说明我的观点,通过诸如此等各种选择来修改诉讼地:

$( option , this).each(function() {
    for (var i = 0; i < this.attributes.length; i++) {
        var pair = this.attributes[i].name +  :  
            + this.attributes[i].value;
        alert(pair);
    }
    selected.push($(this).val());
});

您将看到这些特性如何在<代码>fcbkcomplete之后结束。

http://www.ohchr.org。

我在用“JSON”字眼 setting立后,终于复制了你正在处理的问题。 这就是说,当你使用JSON而不是硬编码时,行为就会发生完全变化。 您的工作解决办法是:

$(document).ready(function() {
    var clicker = function(e) {
        var selected = new Array();

        // using "this" here was out of context, use #select3
        $( option , $( #select3 )).each(function() {
            selected.push(this.value);
        });

        $( #interest ).val(selected.join( ,  ));
    };

    $("#select3").fcbkcomplete({
        json_url: "parseJSON.txt",
        addontab: true,
        maxitems: 10,
        input_min_size: 0,
        height: 10,
        select_all_text: "select",
        onselect: clicker
    }); 
});
问题回答

Below link is example of getting value in fcbkcomplete on select. Same process you can do for id to. https://github.com/emposha/FCBKcomplete/issues/110 example how to use :

`//auto complete jquery starts here
     $("#box").fcbkcomplete({
                    width: 250,
                    addontab: true,                   
                    maxitems: 1,
                    input_min_size: 0,
                    height: 10,
                    cache: true,
                    filter_case: true,
                    filter_hide: true,
                    filter_selected: true,
                    newel: true,
                    filter_case:false,
                    onselect: function(item)
                    {
                        getting_value_dealer(item._value, item._id);
                    }
                });
    //auto complete jquery ends here
`




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签