在进入不改变输入值JQueryMobile自动完成点击 [英] JQueryMobile autocomplete click on entry dont change input value

查看:331
本文介绍了在进入不改变输入值JQueryMobile自动完成点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让使用jQuery Mobile自动完成一个输入。

所以,我发现这个在这里演示:
http://demos.jquerymobile.com/1.4.0/listview-autocomplete-远程/

但我的问题是,我无法通过点击进入上市更改输入字段的值。

我想,如果我点击一个条目列出输入字段的值上像正常的自动完成问题的项目的价值。

下面是一个SSCCE(我不能把页面上的jsfiddle工作,所以我用引擎收录):

http://pastebin.com/QmtEQegF

感谢您的帮助。


解决方案

这是多还是少一样在这个<一个href=\"http://stackoverflow.com/questions/17980018/autocomplete-in-jquery-mobile-text-input\">link.

在您的code,你使用。就绪()而不安装点击事件动态生成。就绪()不建议JQM使用,而是使用的 jQuery Mobile的1.4事件的。

等效事件。就绪() pagecreate ,因为它替换 pageinit 在JQM 1.3.2及以下。

 的$(document)。在(pagecreate,#startseite功能(){  / *从李点击文本检索* /
  $(文件)。在(点击,礼,函数(){
    变种文字= $(本)的.text();
    $(本).closest(UL)preV(形式)找到(投入)VAL(文本)。;
  });  $(#自动完成)。在(filterablebeforefilter功能(即数据){
    / * code *的休息/
  });
});


  

演示


I try to make a autocomplete input with jquery mobile. '

So I found a demo for this here: http://demos.jquerymobile.com/1.4.0/listview-autocomplete-remote/

But my problem is, that I cant change the value of the input field by clicking on a listed entry.

I want that if I click on a listed entry the value of the input field gets the value of the entry like the normal autocomplete behavior.

Here is a SSCCE (I couldnt bring the page to work on jsfiddle so I used pastebin):

http://pastebin.com/QmtEQegF

Thanks for any help

解决方案

It is more or less the same as in this link.

In your code, you're using .ready() and not attaching click event to dynamically generated li. .ready() isn't recommended to be used in jQM, instead, use jQuery Mobile 1.4 events.

The equivalent event to .ready() is pagecreate as it replaces pageinit in jQM 1.3.2 and below.

$(document).on("pagecreate", "#startseite", function () {

  /* retrieve text from clicked li */
  $(document).on("click", "li", function () {
    var text = $(this).text();
    $(this).closest("ul").prev("form").find("input").val(text);
  });

  $("#autocomplete").on("filterablebeforefilter", function (e, data) {
    /* rest of code */
  });
});

Demo

这篇关于在进入不改变输入值JQueryMobile自动完成点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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