私はAndroidアプリを作成していて、2つのボタンがあります。1スタートと1ストップ。スタートボタンをクリックすると停止ボタンが表示され、停止ボタンが表示され、開始が非表示になります。
STOPボタンでタッチスタートイベントを取得しようとしています(スタートボタンにも追加するのが好きですが、必須ではありません)。ただし、何らかの理由で、以下のコードが正しく機能していません。私が見逃したことを教えてください。
背景:-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">