简体   繁体   中英

Phonegap Touch Event Handling

I am trying to make a calculator using phonegap - but I am running into problems in adding the touch event. It does not show anything on the display. kindly see if there are problems in the code. and suggest me a solution. **I have added the onTouch event to all the numbers and math operators buttons.

function onload(){
        document.getElementById("display").addEventListener('onTouch',insert,false);
        document.getElementById("clear").addEventListener('onClear', clear, false);
        document.getElementById("equal")addEventListener('onEqual', evaluate,false);
    }

function clear(){
    document.getElementById("display").value="";
    return false;
}
function insert(val){
    document.getElementById("display").value+=val;
}
function evaluate(){
    try
    {
        ans= eval(document.getElementById("display").value);
        document.getElementById("display")=ans;
        return false;
    }
    catch
    {
        document.getElementById("display").value="Error";
        return false;
    }
}

I am not sure about the onTouch event. Does that exist at all?

I would suggest to try either touchstart or touchend maybe touchmove event handlers. These should work. For example:

document.getElementById("display").addEventListener('touchstart',insert,false);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM