搜索按钮适用于模拟器,但不适用于设备 - jQTouch 和 PhoneGap
我已经在 iPhone 应用程序中设置了基本搜索功能。它的工作原理是 它应该在模拟器上,但是当在设备上使用该应用程序时, 点击搜索按钮时不会执行任何操作。我已经尝试过 有很多事情可以让它发挥作用(onsubmit等),但没有任何效果。 有人可以帮忙吗?
这是我的搜索功能和形式:
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="if (event.keyCode == 13) getData(this.form)" 删除它会使其停止在模拟器中工作。
I've setup a basic search function within my iPhone app. It works as
it should on the simulator but when using the app on the device, the
search button doesn't do anything when it is tapped. I have tried
numerous things to get it to work (onsubmit, etc.) but nothing works.
Can anybody help?
Here is my search function and the form:
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>
I should mention, the only reason it works on the simulator is because of:
onkeydown="if (event.keyCode == 13) getData(this.form)"
Removing that will make it stop working in simulator.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
苹果在 iOS 4.2 中“修复”了这个问题。对于要获取 onsubmit 事件的表单,必须有一个 type="submit" 的输入标记。
Apple "fixed" this in iOS 4.2. For a form to get onsubmit events, there has to be an input tag with type="submit".