如何实现在javascript中的搜索功能phonegap? [英] how to implement search functionality in javascript for phonegap?

查看:125
本文介绍了如何实现在javascript中的搜索功能phonegap?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在java脚本中实现一个搜索功能。我是新的java脚本。我在下面的代码中犯了任何错误forgive我。





javascript

p>

  $(#input)。keyup(function(){
var userInput = $(this).val );
$(#list div)。map(function(index,value){
$(value).toggle($(value).text()。toLowerCase()。indexOf userInput)> = 0);
});

});



但是,CORDOVA没有识别$ ...因此,当我实现此类

  document.getElementById(input)。keyup(function(){
var userInput = val();
document.getElementById(main div) .map(function(index,value){
document.getElementById(value).toggle(document.getElementById(value).text()。toLowerCase()。indexOf(userInput)> = 0);

现在,我收到一个错误

  05-30 11:59:18.500:INFO / Web控制台(930):JSCallback错误:TypeError:表达式document.getElementById ).keyup'[undefined]不是一个函数。在file:///android_asset/www/cordova-2.1.0.js:3727 

html



 < input type =textid =input/> 
< div id =list>
< div> Rich< / div>
< div> Rajim< / div>
< div> vimal< / div>
< div> RAGHU< / div>
< / div>

请给我一个解决方案。

解决方案

问题是你不包括JQuery。一旦你包括它,它的工作。 jsfiddle这里: http://jsfiddle.net/Y49EW/

  $(#input)。keyup(function(){
var userInput = $(this).val();
console.log (this);
$(#list div)。map(function(index,value){
$(value).toggle($(value).text()。toLowerCase ).indexOf(userInput)> = 0);
});
});

要包括jQuery:



从这里下载jquery(选择版本): http://jquery.com/download/



2)将其添加到HTML页面的 head 标记中

 < script type =text / javascriptsrc =jquery-versionyouchoosed.js>< / script> 

例如,如果您使用1.9.1版本,则需要使用 -

 < script type =text / javascriptsrc =jquery-1.9.1.js>< / script& 


I want to implement a search functionality in java script.I am new to java script.if i have committed any blunder in the code below forgive me.

How should I implement it?

I tried implementing like this

javascript

$("#input").keyup(function() {
var userInput = $(this).val();
$("#list div").map(function(index, value) {
    $(value).toggle($(value).text().toLowerCase().indexOf(userInput) >= 0);
});

});

BUT,CORDOVA EITHER DOES NOT RECOGNIZE $...SO WHEN i IMPLEMENTED IT LIKE THIS

document.getElementById("input").keyup(function() {
                var userInput = val();
                document.getElementById("main div").map(function(index, value) {
                document.getElementById(value).toggle(document.getElementById(value).text().toLowerCase().indexOf(userInput) >= 0);

NOW, I GET an error as

05-30 11:59:18.500: INFO/Web Console(930): JSCallback Error: TypeError: Result of expression 'document.getElementById("input").keyup' [undefined] is not a function. at file:///android_asset/www/cordova-2.1.0.js:3727

html

<input type="text" id="input"/>
<div id="list">
<div>Rich</div>
<div>Rajim</div>
<div>vimal</div>
<div>RAGHU</div>
</div>

Please,suggest me a solution to work on.

解决方案

The problem is that you're not including JQuery. As soon as you include it, it works. jsfiddle here: http://jsfiddle.net/Y49EW/

$("#input").keyup(function () {
    var userInput = $(this).val();
    console.log("here");
    $("#list div").map(function (index, value) {
        $(value).toggle($(value).text().toLowerCase().indexOf(userInput) >= 0);
    });
});

To include jQuery:

1) download jquery (choose a version) from here: http://jquery.com/download/

2) add this into the head tag of your html page

 <script type="text/javascript" src="jquery-versionyouchoosed.js"></script>

For example, if you are using 1.9.1 version, you need to use-

 <script type="text/javascript" src="jquery-1.9.1.js"></script>

这篇关于如何实现在javascript中的搜索功能phonegap?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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