Html onclick在Android中两次开火

use*_*307 5 html android onclick

码:

function hello(){alert("Hi");}; 

<center> 
<table border="0" height="100%">
<tbody>
            <tr>
                <td align="center" width="100%">
                <img src="cover.png"
                    width="300" height="300" id="image"></img></td>
            </tr>
            <tr>
                <td height="100%">&nbsp;</td>
            </tr>
            <tr>
                <td align="center">
             <form onsubmit="go();return false">  
                        <input class="answer" id="answer" name="answer"
                             onclick="hello();"/>
                  </form> 
                </td>
            </tr>
            <tr>

            </tr>
        </tbody>
</table>
</center>
Run Code Online (Sandbox Code Playgroud)

我一直在尝试捕获HTML中单击答案文本框的时间.它在Firefox和Chrome中完美运行(我只获得一个Hi警报),但是当我尝试在android中的Web视图中运行代码时,onclick方法会触发两次(我得到两个Hi警报).但是,当我稍后调用相同的功能时,它可以正常工作,只发出一个Hi警报.

<div style="bottom: 0; right: 0; position:absolute;  margin-right:5%">
    <a><img alt="" src="start.png" id="submit" onclick="go();hello();"></a>
    </div>
Run Code Online (Sandbox Code Playgroud)

我猜这与我从表单内部调用函数的事实有关,它以某种方式触发事件两次,但我不知道如何解决它.有帮助吗?

chr*_*dam 0

您可以尝试使用one()如下。

$('#answer').one('click', function() {
    alert("Hi");
});

<form onsubmit="go();return false">  
   <input class="answer" id="answer" name="answer"/>
</form>
Run Code Online (Sandbox Code Playgroud)