我正在创建一个 Android 应用程序并有 2 个按钮。1个开始和1个停止。单击开始按钮后,停止按钮开始可见,然后停止按钮变为可见并开始不可见。
我试图在 STOP 按钮上获得一个 touchstart 事件(也可以添加到开始按钮,但不是必需的)。但是,由于某种原因,我的以下代码无法正常工作。有些人可以让我知道我错过了什么。
背景: - 使用 jquery 隐藏我的按钮 - 带有背景图像的按钮
JAVASCRIPT:
var b=document.getElementById('STOP'),start=0;
//Check for touchstart
if('ontouchstart' in document.documentElement)
{
document.getElementById("notouchstart").style.display = "none";
}
//Add a listener that fires at the beginning of each interaction
[b].forEach(function(el){el.addEventListener('touchstart',interact);});
//Add the event handlers for each button
b.addEventListener('touchstart',highlight);
//Functions Store the time when the user initiated an action
function interact(e)
{
start = new Date();
}
//Highlight what the user selected and calculate how long it took the action to occur
function highlight(e)
{
e.preventDefault();
e.currentTarget.className="active";
if(start)
{
alert("test")
}
start = null;
}
HTML 按钮:
<INPUT TYPE="button" style="background:url(images/Start_Btn.png); background-color:transparent; width:150px; height:186px; border:none; cursor:pointer;" id="START" onClick="startBTN();">
<INPUT TYPE="button" style="background:url(images/Stop_Btn.png); background-color:transparent; width:150px; height:186px; border:none; cursor:pointer;" id="STOP">