[英]how to implement search functionality in javascript for phonegap?
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. 我想在Java脚本中实现搜索功能。我是Java脚本的新手。如果我在下面的代码中犯了任何错误,请原谅。
How should I implement it? 我应该如何实施?
I tried implementing like this 我试图像这样实现
javascript 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 但是,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);
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 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. 问题是您不包括JQuery。 As soon as you include it, it works.
一旦包含它,它就会起作用。 jsfiddle here: http://jsfiddle.net/Y49EW/
jsfiddle在这里: 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: 要包括jQuery:
1) download jquery (choose a version) from here: http://jquery.com/download/ 1)从此处下载jquery(选择版本): http : //jquery.com/download/
2) add this into the head
tag of your html page 2)将其添加到您的html页面的
head
标签中
<script type="text/javascript" src="jquery-versionyouchoosed.js"></script>
For example, if you are using 1.9.1 version, you need to use- 例如,如果您使用的是1.9.1版本,则需要使用-
<script type="text/javascript" src="jquery-1.9.1.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.