This Is first time,I am working on mobile based Application.We finished an Application,it supports both desktop and tablet
.If you open same Application in Mobile
,it's not appearing properly.So we decided to change way of show the Application in mobile compare with desktop and tablet.As per specs my HTML
guy made mobile pages.
In backbone side,I don't need to change model
events.I am facing a problem in view events especially keyboard
events.What I written same code working fine in desktop and tablet
but it's not working in mobile
.
Code:
events:{"keypress input[type=text]":"typeOfField"},
typeOfField:function(){
//finding Ascii value of the press key
var keyAsciiValue=event.keyCode||event.which;
//declaring dummy variable for passing result
var result=false;
if ((keyAsciiValue>=48&&keyAsciiValue<=57)||(keyAsciiValue===46)||(keyAsciiValue===45)){
//text-field allows any numbers like 23.8,30...
result=true;
}else{
result=false;
}
return result;
}
code description:
If user press on any key,fetching corresponding ASCII
value and checking whether the key is character or number.If it is number then only returning true
otherwise returning false
.Finally in my application textFields
allows only numbers
.
What I am facing problems:
textField
allowing all the values(like characters,numbers ...)
I can't able to delete the last character.
If mobile
events are different compare with desktop,tablet
events,can you suggest any tutorials for my reference.
I googled but I didn't find any tutorials.
For your testing,I made jsFiddle .If you open this link in desktop or tablet
it's working fine as per specs.But it's not working in mobile
.It's allowing characters
also in mobile
.
Thanks.
It seems that keypress event is not fired in Android before you confirm your input. You may use keyup event for your task.
For the second problem, it should be just because the events are not fired correctly as expected.
最后我发现了一个问题,但是它在opera
不起作用。我没有写数字字段的代码。我只是在HTML文件的输入字段中添加了一个属性type='number'
。现在只有numeric
小键盘来了。满足我的要求。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.