如何实现的onclick在JavaScript和HTML与较低的Andr​​oid版本的设备? [英] How to implement onclick in javascript and html for devices with lower versions of android?

查看:178
本文介绍了如何实现的onclick在JavaScript和HTML与较低的Andr​​oid版本的设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我上高完全在设备的一个项目工作版本,我在4.1.2版本检查了。

I am working on a project which works perfectly in devices with higher version-I have checked it in 4.1.2 version.

问题是,它不是在与Android版本2.2.1和2.3.5设备的正常工作。

The problem is that it is not working in devices with android version 2.2.1 and 2.3.5.

我有六幅图像,我已经添加功能,以。 2图像的功能是调用不同的HTML页面的id值。对于其他四个图像的功能也是相同的,但是图像将显示基于数据库值

I have six images to which I have added functionalities. The functionality for 2 images is to call a different HTML page with the id value. The functionality for the other four images is also the same,BUT the images will display based on the database value.

2图像的功能是调用不同的HTML页面的id值。

这是我怎么也得codeD ..

This is how I have coded..

<div id="header " class="header ">
     <div id="header_title" class="header_title"> </div>
     <div id="abc" class="abc"><img src="img/abc.png" onClick="abc()"/></div>
-----so -on

我已经宣布了ABC功能

I have declared the abc function as

function abc(){
   window.location.href="index.html";
}

对于其他四幅图像的功能也是相同的,但图像显示会根据数据库值。

if(value_in_db==0) {
  document.getElementById("xyz").innerHTML = '<img src="img/inactive.png" />'
} else {
  document.getElementById("xyz").innerHTML = '<img src="img/active.png" onclick="xyz()"/> '
}

我已经宣布了XYZ功能

I have declared the xyz function as

function xyz(){
   window.location.href="basic.html";
}

面对的问题:

的onclick功能功能曾经在Android版本2.2.1一会儿2.3.5.when不断尝试单击突然函数被调用。我已经尝试了几乎2天修复此错误的。

The onclick functionality functions once in a while in android version 2.2.1 and 2.3.5.when keep on trying to click suddenly the function is called. I have tried fixing this error for almost 2 days.

我曾面对CSS的位置类似的问题:固定的。这不是在较低的版本android.I支持用溶液<一个建议href=\"http://stackoverflow.com/questions/16957930/how-to-fix-this-sticky-footer-for-android-devices-in-phone-gap\">here.

I had faced a similar problem with the CSS position:fixed. This was not supported in the lower versions of android.I was suggested with a solution here.

我试图与这的addEventListener功能它没有为我工作。

I have tried with this addEventListener function it did not work for me.

我希望我能为这个问题的解决方案。

I hope I get a solution for this problem to.

请帮我解决这个问题,引导我!

Please help me to fix this and guide me!

编辑:1的TouchEvent和deviceready

document.addEventListener("deviceready", onDeviceReady, false);
document.addEventListener( "touchstart", function(e){ onStart(e); }, false );
function onStart ( touchEvent ) 
{
   if( navigator.userAgent.match(/Android/i) ) 
   {
        touchEvent.preventDefault();
   }
}

这个工作在较高端的版本,但不是在下端的版本。我知道它毫无根据提2 document.addEventListener ..因为它工作在较高versions.i继续吧。

This works in the higher end version but not in the lower end version. I know its baseless to mention 2 document.addEventListener..as it worked in the higher versions.i continued it.

推荐答案

这是pretty基本功能,并应在Android所有版本的 - 你确定这不是别的东西在你的code引起的问题?

This is pretty basic functionality and should work on all versions of Android - are you sure it's not something else in your code causing the problem?

我尝试使用最新的科尔多瓦在其上运行的是Android 2.3.4我的HTC HD2 2.8.0本测试案例和它的作品一贯罚款:

I tried this test case using the latest Cordova 2.8.0 on my HTC HD2 which is running Android 2.3.4 and it works consistently fine:

<!DOCTYPE html>
<html>
    <head>     
        <meta charset="utf-8">
        <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
        <script type="text/javascript">
            function abc(){
               window.location.href="foo.html";
            }
        </script>
    </head>
    <body>
         <h1>Index page</h1>
         <div id="abc" class="abc"><img src="img/abc.jpg" onClick="abc()"/></div>
    </body>
</html>

您可以下载我的Eclipse测试项目并编译APK 这里并尝试在你的设备上。

You can download my Eclipse test project and compiled APK here and try it on your devices.

根据您的jsfiddle code更新:

您的HTML包含几个语法错误 - 其中之一可能是造成与Android 2.x的问题,而4.x版可能会更容错:

Your HTML contains several syntax errors - one of these may be causing issues with Android 2.x whereas 4.x may be more error tolerant:

1)的#header ID属性包含尾随空白。替换

1) The #header id attribute contains trailing whitespace. Replace

&LT; D​​IV ID =头级=头&GT;

&LT; D​​IV ID =头级=头&GT;

2)的属性值应该被引用。替换&LT; IMG NAME =幻灯片SRC =IMG / abc.jpg的WIDTH = 100%; /&GT; &LT; IMG NAME =幻灯片SRC =IMG / abc.jpg的WIDTH =100%/&GT;

2) Attribute values should be quoted. Replace <img name="slide" src="img/abc.jpg" width=100%; /> with <img name="slide" src="img/abc.jpg" width="100%" />

3)你有一个额外的闭幕div标签。替换

3) You have an extra closing div tag. Replace

<div id="footer"  class="footer">
    <div id="footer_text" style="color:#ffffff">footer</div>
    </div>
</div>

<div id="footer"  class="footer">
    <div id="footer_text" style="color:#ffffff">footer</div>
</div>

这篇关于如何实现的onclick在JavaScript和HTML与较低的Andr​​oid版本的设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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