Android Webview按钮不工作

Android Webview buttons not working

本文关键字:工作 按钮 Webview Android      更新时间:2023-09-26

我正在制作一个html应用程序,并在Android的webview中运行它。在我的三星s3 mini和我测试过的其他几个设备上,一切都像预期的那样完美,但是按键在其他一些设备上没有效果(例如htc wildfire…我正在查找哪些设备不能工作)。

按钮的css格式为:

button {
    -moz-box-shadow:inset 0px 1px 10px 0px #000000;
    -webkit-box-shadow:inset 0px 1px 10px 0px #000000;
    box-shadow:inset 0px 1px 10px 0px #000000;
    background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #00ff00), color-stop(1, #00ff00) );
    background:-moz-linear-gradient( center top, #00ff00 5%, #00ff00 100% );
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#00ff00', endColorstr='#00ff00');
    background-color:#00ff00;
    -webkit-border-top-left-radius:42px;
    -moz-border-radius-topleft:42px;
    border-top-left-radius:42px;
    -webkit-border-top-right-radius:42px;
    -moz-border-radius-topright:42px;
    border-top-right-radius:42px;
    -webkit-border-bottom-right-radius:42px;
    -moz-border-radius-bottomright:42px;
    border-bottom-right-radius:42px;
    -webkit-border-bottom-left-radius:42px;
    -moz-border-radius-bottomleft:42px;
    border-bottom-left-radius:42px;
    text-indent:0px;
    border:1px solid #006400;
    display:inline-block;
    color:#000000;
    font-family:Arial;
    font-size:1.2em;
    font-weight:bold;
    font-style:normal;
    line-height:46px;
    text-decoration:none;
    text-align:center;
    text-shadow:1px 1px 0px #00ff00;
    width:7em;
}
button:hover {
    background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #00ff00), color-stop(1, #00ff00) );
    background:-moz-linear-gradient( center top, #00ff00 5%, #00ff00 100% );
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#00ff00',         endColorstr='#00ff00');
    background-color:#00ff00;
}
button:active {
    position:relative;
    top:1px;
}

,其中一个按钮有:

.button-wrap {
    width:auto;
}

有趣的是,带有class="button-wrap"的按钮是唯一在一个设备上工作的按钮。

按钮的HTML很简单:

<button class="button-list-spacing" id="play-game-button">Play!</button>

和它们后面的js是:

$("#play-game-button").click(function (e) {
    window.location.replace("gamepage.html?soundon=" + SOUND_ON);
});

有没有人知道什么东西会导致按钮不响应点击?我将来会编辑一个列表,列出它可以工作的设备,以及它不能工作的设备。

编辑:

按钮不工作*三星galaxy tab 7.0 GT-P6200, Android版本3.2

这里是小提琴:http://jsfiddle.net/Yuy7F/

我在这里贴了一个相关的问题,可能值得一看:https://stackoverflow.com/questions/22595810/android-webview-messes-up-in-4-1-1-but-not-4-1-2

显然你正在使用像jquery这样的框架。

确保框架的所有javascript文件可用,或者试试这个:

<button class="button-list-spacing" id="play-game-button" onclick="window.location.replace("gamepage.html?soundon=" + SOUND_ON);">Play!</button>

并使surevthe SOUND_ON变量可用