onClick事件的JavaScript不工作在移动设备 [英] onClick event of javascript not working in mobile device

查看:97
本文介绍了onClick事件的JavaScript不工作在移动设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的JSP页面中,我使用 onkeypress =return event.charCode> = 48&& event.charCode< = 57来仅允许号码。它与网站浏览器工作正常。好吧,它不支持在移动设备浏览器(谷歌铬)。我已经启用JavaScript执行。我尝试了这个答案,但没有任何反应。我还有一个问题,它将计算输入标记中的值,如果该值超过4999,它将显示另一个输入标记,但它也不适用于移动设备。如何解决这个问题?



这里是代码,

第一个按钮输入值,它只接受数字值

 < input type =textname =amount1id =uploadonkeypress =return event。 charCode> = 48&& event.charCode< = 57&& showFile()required /> 

隐藏按钮,当值超过4999时显示

 < div id ='openfile'style ='display:none'>< input type =fileclass =form-controlname =panImg1placeholder =上传您的pancard图片/>< / div> 

脚本文件

 < script type =text / javascript> 
function showFile()
{
var choice = document.getElementById('upload')。value;
if(choice> 4999)
{
document.getElementById('openfile')。style.display ='block';
} else
{
document.getElementById('openfile')。style.display ='none';
}
}
< / script>


解决方案

我认为JavaScript可能无法在输入标签的onKeypress在某些手机的谷歌Chrome浏览器中,如果出现此问题,请使用jquery获得更好的性能,
这里的代码帮助我 $(document).ready(function(){
$ #upload)。on('input',function(){
if(v> 40000){

var v =var v =< div id ='appDiv 'class ='col-md-4 inputGroupContainer'>< input required =''type ='text'name ='panImg1'/>< / div>;
$('#newDiv' ).append(v);
}
});
});



在页面中的Div
< div id =newDiv>< / div> 。在这种类型情况下使用jquery获得更好的结果。感谢您的帮助我。


In my JSP page, I am using onkeypress="return event.charCode >= 48 && event.charCode <= 57 " to allow only the numbers. It is working fine with the website browsers.Well, it's not supported in mobile device browser(Google chrome).I have enabled javascript to execute. I tried this answer, but nothing happens. I have another issue, which will calculate the value in input tag, if the value is above 4999, it will display another input tag,it also not working in the mobile device. How can I resolve this?

Here is the code,

First button to enter values,which accepts only digit values

<input type="text" name="amount1" id="upload" onkeypress="return event.charCode >= 48 && event.charCode <= 57 && showFile()" required />

Hidden button,displayed when value is above 4999

<div id='openfile' style='display:none'><input type="file" class="form-control" name="panImg1" placeholder="Upload Your pancard image"  /></div>

Script file

<script type="text/javascript">
        function showFile()
        {
            var choice = document.getElementById('upload').value;
            if (choice > 4999)
            {
                document.getElementById('openfile').style.display = 'block';
            } else
            {
                document.getElementById('openfile').style.display = 'none';
            }
        }
    </script>

解决方案

I think javascript may not work in onKeypress of input tabs in some mobile phone's google chrome browser,if this problem arise use jquery for better performance, here this code helped me $(document).ready(function () { $("#upload").on('input', function () { if (v > 40000) {
var v = "var v = "<div id='appDiv' class='col-md-4 inputGroupContainer'><input required='' type='text' name='panImg1' /></div>"; $('#newDiv').append(v); } }); });

and added a Div in page <div id="newDiv"></div>.In this type situations use jquery for better results.Thanks for helping me.

这篇关于onClick事件的JavaScript不工作在移动设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆