JQueryMobile autocomplete click on entry dont change input value

落花浮王杯 提交于 2020-01-01 17:13:41

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/20821583/jquerymobile-autocomplete-click-on-entry-dont-change-input-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!