在特定情况下自动完成的jQuery [英] Jquery autocomplete on select event

查看:130
本文介绍了在特定情况下自动完成的jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jQuery的自动完成和它做工精细,现在我想给一个变量在会话存储从jQuery的当出现以下情况

i am using jquery autocomplete and its working fine , now i want to store a variable in session from jquery when following condition occurs

当有人类型的任何单词的jQuery显示建议下拉列表,如果有人选择从建议下拉列表中的项目

when someone types any word jquery shows suggestion dropdown , if someone select an item from that suggestion dropdown

我要捕捉上述点和变量存储在会话

i want to capture above point and store a variable in session

我搜索谷歌,但计算器找到我的code为自动完成是继无培训相关的解决方案。

i searched google , stackoverflow but find no relevent solution my code for autocomplete is following

  $(".autosearch-smart").autocomplete('Home/GetCompanyNames', {
    minChars: 1,
    width: 402,
    matchContains: "word",
    autoFill: true
});

,这就是我试图做

and this is what i tried to do

  $(".autosearch-smart").autocomplete('Home/GetCompanyNames', {
    minChars: 1,
    width: 402,
    matchContains: "word",
    autoFill: true,
    select: function (a, b) {
        alert("selected");
    }

});

编辑:选择事件处理程序也无法正常工作

我使用asp.net MVC3用C#。请帮我感谢在前进。

I am using asp.net mvc3 with c# . Please help me out and thanks in advance .

推荐答案

所以,如果我理解正确的话,你要选择的值存储在一个变量会话

So if I understand correctly you want to store the selected value in a variable sessions

您可以通过以下code走出选定项的值:

you can get the value out of the selected item through following code:

  $(".autosearch-smart").autocomplete('Home/GetCompanyNames', {
minChars: 1,
width: 402,
matchContains: "word",
autoFill: true,
select: function (event, ui) {
    var label = ui.item.label;
    var value = ui.item.value;
   //store in session
  document.valueSelectedForAutocomplete = value 
}
});

值和标签是从服务器

the value and label are json objects that came from the server

希望这有助于

这篇关于在特定情况下自动完成的jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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