cordova:触摸时向按钮添加事件监听器

时间:2017-03-08 10:46:11

标签: cordova events

我对Cordova很新。我只是尝试在用户触摸时向按钮添加一个事件:

var app = {
    initialize: function() {
        document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
    },
    onDeviceReady: function() {
        this.receivedEvent('deviceready');
    },
    receivedEvent: function() {
        ....
        myButtonElement.addEventListener('click', app.authenticationBtnClicked(), false);
    },
    authenticationBtnClicked: function() {
        alert('hello');
    }
}

app.initialize();

它不起作用。

我也试过这些线,但它没有用更多的东西:

    myButtonElement.addEventListener('click', function() { alert('salut'); }, false);
    myButtonElement.addEventListener('touchstart', app.authentificationBtnClicked(), false);
    myButtonElement.addEventListener('touchend', app.authentificationBtnClicked(), false);

所以我决定忘记javascript addEventLister并将onclick属性放到我的html按钮标记中:

<button onclick="app.authenticationBtnClicked()">Authenticate</button>

它也不起作用。

我该怎么办?

0 个答案:

没有答案
相关问题