我正在尝试此链接 http://jsfiddle.net/QRj83/让它在我的phonegap应用程序上工作。这些代码在网站中可以正常工作,但在phonegap应用程序中却不能正常工作。没有显示错误,奇怪的是为什么不起作用。有人在phonegap中遇到过这个问题吗?
这是我的js代码:
$('input').keyup(function(e) {
if(e.keyCode == 13) {
$(this).next().focus();
}
});
HTML 代码:
<input type="textbox" />
<input type="textbox" />
<input type="textbox" />
谢谢。
最佳答案
<!DOCTYPE html>
<html>
<body>
<input type="textbox" id="text1" name="text1" />
<input type="textbox" id="text2" name="text2" />
<input type="textbox" id="text3" name="text3" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script>
var name="text";
var count=3;
$( document ).ready(function() {
setIndex();
});
function setIndex() {
for(var i=1;i<=count;i++)
{
document.getElementById(name+i).tabIndex = i;
document.getElementById(name+i).onkeypress = function(event) {
myFunction(event);
}
}
}
function myFunction(event) {
var x = event.which || event.keyCode;
if(x==13)
{
var item=event.target.id;
var tabIndex=parseInt(item.replace(name,""));
if(tabIndex==count)
{
document.getElementById(name+1).focus();
}
else
{
tabIndex=tabIndex+1;
document.getElementById(name+tabIndex).focus();
}
}
}
</script>
</body>
</html>
关于javascript - 电话间隙中的文本框焦点不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37526225/