解决input[type=number]无法显示非数字字符的问题
2013-04-01 13:04
585 查看
在移动端webview实现的页面中,有数字的地方必须使用input type="number"类型的input,否则触发后的键盘为全键盘,而非数字键盘。但另外的一个问题是,input 为 type="number" 类型的无法显示非数字字符,比如:12/23中/。
只能采取另外的思路来解决,比如:显示的时候用非number类型的input或其它元素,当触发onfocus后,利用js 动态修改为number类型。
<input class="pg-page-num" type="text" name="" value="34/233" id="pageNum">
<input type="hidden" name="" value="25" id="totalPage">
<script type="text/javascript">
var oPage = document.querySelector('#pageNum'),
oTotal = document.querySelector('#totalPage'),
sOldVal = '';
oPage.addEventListener('focus', function () {
this.type = 'number';
sOldVal = this.value;
}, false);
oPage.addEventListener('blur', function () {
var sVal = this.value;
this.type = 'text';
if (sVal != sOldVal) {
this.value += '/' + oTotal.value;
}
}, false);
</script>
只能采取另外的思路来解决,比如:显示的时候用非number类型的input或其它元素,当触发onfocus后,利用js 动态修改为number类型。
<input class="pg-page-num" type="text" name="" value="34/233" id="pageNum">
<input type="hidden" name="" value="25" id="totalPage">
<script type="text/javascript">
var oPage = document.querySelector('#pageNum'),
oTotal = document.querySelector('#totalPage'),
sOldVal = '';
oPage.addEventListener('focus', function () {
this.type = 'number';
sOldVal = this.value;
}, false);
oPage.addEventListener('blur', function () {
var sVal = this.value;
this.type = 'text';
if (sVal != sOldVal) {
this.value += '/' + oTotal.value;
}
}, false);
</script>
相关文章推荐
- 完美解决input[type=number]无法显示非数字字符的问题
- input type=number 无法识别非数字的解决办法
- 移动端限制两位小数并且弹出数字键盘(解决使用H5S使用input[type='number']不兼容JS的问题)
- BUG笔记:Win8 IE10下input[type="password"]内字符显示被截取问题
- 解决 安装SLES11 for IA64 无法显示的问题(input non support)
- fastclick插件 导致 input[type="date"] 无法触发问题解决方案
- 理解SQLSERVER中的排序规则,解决无法正确显示中文字符的问题
- 解决JS(Vue)input[type='file'] change事件无法上传相同文件的问题
- 解决boostrap字符图标无法显示问题
- 解决 iphone 下面 input type="search" 弹出虚拟键盘 不能显示 搜索 问题
- 理解SQL SERVER中的排序规则,解决项目中无法正确显示中文字符的问题
- 理解SQLSERVER中的排序规则,解决无法正确显示中文字符的问题
- Android 4.1.2 input type number时placeholder不显示的问题
- 理解SQLSERVER中的排序规则,解决无法正确显示中文字符的问题
- andriod InputType.TYPE_NUMBER_FLAG_DECIMAL只能输入数字和小数点无效问题
- .net 2.0 中对于非服务器端的input元素 type为file后台无法获取的问题的解决方法
- BUG笔记:Win8 IE10下input[type="password"]内字符显示被截取问题
- 读取excel文件显示在gridview中数据.字符.数字混合时无法全部读取的问题!
- Visual Studio 2008项目中WinForm窗体图标显示为类图标,只能打开代码而无法打开视图问题解决
- [Android]浮层视频效果,在另外一个Window使用SurfaceView无法正常显示的问题排查与解决