[英]how to implement search functionality in javascript for phonegap?
我想在Java腳本中實現搜索功能。我是Java腳本的新手。如果我在下面的代碼中犯了任何錯誤,請原諒。
我應該如何實施?
我試圖像這樣實現
javascript
$("#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 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>
請給我建議一個解決方案。
問題是您不包括JQuery。 一旦包含它,它就會起作用。 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);
});
});
要包括jQuery:
1)從此處下載jquery(選擇版本): http : //jquery.com/download/
2)將其添加到您的html頁面的head
標簽中
<script type="text/javascript" src="jquery-versionyouchoosed.js"></script>
例如,如果您使用的是1.9.1版本,則需要使用-
<script type="text/javascript" src="jquery-1.9.1.js"></script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.