搜索按钮适用于模拟器但不适用于设备 - jQTouch和PhoneGap

时间:2011-03-16 17:24:54

标签: javascript iphone search cordova jqtouch

我在iPhone应用程序中设置了基本搜索功能。它起作用 它应该在模拟器上,但在设备上使用应用程序时, 点击时,搜索按钮不会执行任何操作。我试过了 许多事情让它工作(提交等)但没有任何作用。 有人可以帮忙吗?

这是我的搜索功能和表格:

function recipeInfo(name, ingredients, url) {   
this.name = name;  
this.ingredients = ingredients;
this.url = url;
}

var vIngredients = new Array();
vIngredients[0] = new recipeInfo("Ackee Pasta", "ackee", "ackpast.html");
vIngredients[1] = new recipeInfo("Ackee and Saltfish", "ackee saltfish", "acksalt.html");
vIngredients[2] = new recipeInfo("Jerk Chicken", "jerk", "jerkchick.html");

// do the lookup
function getData(form) {
    // make a copy of the text box contents
    var inputText = form.Input.value
    var list = $("#search-results");
    list.empty();
    // loop through all entries of vIngredients array
    for (var i = 0; i < vIngredients.length; i++) {
        // compare results
        if (vIngredients[i].ingredients.indexOf(inputText) != -1) {
        var found = true;
        console.log(vIngredients[i].name);
        //add to the list the search result plus list item tags
        list.append (
        $("<li class='arrow'><a href='#' >" + vIngredients[i].name + "</a></li>" )
        );
        }
    }
}
</script>

<form id="search" action="" onsubmit="getData(this.form);">
    <ul class="rounded">
        <li><input type="search" name="Input" placeholder="Search..." onkeydown="if (event.keyCode == 13) getData(this.form)"></li>
    </ul>
    <ul class="edgetoedge" id="results">
        <li class="sep">Results</li>
    </ul>
        <ul class="edgetoedge" id="search-results">
    </ul>
</form>

我应该提一下,它在模拟器上工作的唯一原因是因为:     onkeydown =&#34; if(event.keyCode == 13)getData(this.form)&#34; 删除它将使其停止在模拟器中工作。

1 个答案:

答案 0 :(得分:1)

Apple在iOS 4.2中“修复”了这个问题。对于获取onsubmit事件的表单,必须有一个type =“submit”的输入标记。