【问题标题】:How I can use Buttons in a cordova application?如何在 cordova 应用程序中使用按钮?
【发布时间】:2017-01-19 14:13:58
【问题描述】:

您好,我想用两个按钮构建一个 cordova 应用程序。

我有一个插件可以在我的 android 应用程序中显示祝酒词。

如果我点击按钮,我看不到 toast,但我执行没有按钮的代码,我可以看到 toast。

这是我的 index.html:

<div id="deviceready" class="blink">
    <p class="event listening">Connecting to Device</p>
    <p class="event received">Device is Ready</p>

    <button onclick="setShortToast()">
        Kurz
    </button>

    <button onclick="setLongToast()">
        Lang
    </button>

</div>

这是我的 index.js:

var app = {
    // Application Constructor
    initialize: function() {
        document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
    },

    // deviceready Event Handler
    //
    // Bind any cordova events here. Common events are:
    // 'pause', 'resume', etc.
    onDeviceReady: function() {
        this.receivedEvent('deviceready');
    },

    // Update DOM on a Received Event
    receivedEvent: function(id) {
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');

        console.log('Received Event: ' + id);
    },

    setShortToast: function () {
        window.simpleToastPlugin.show("Hallo", 0, function(e){
            //success callback
        }, function(e){
            //error callback
        });
    },

    setLongToast: function() {
        window.simpleToastPlugin.show("Hallo", 1, function(e){
            //success callback
        }, function(e){
            //error callback
        });
    }
};

app.initialize();

【问题讨论】:

    标签: javascript android html cordova events


    【解决方案1】:

    验证 JS 是否已加载并尝试调用 app.setShortToast()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-03
      • 2017-10-07
      • 1970-01-01
      • 2017-09-03
      • 2018-04-22
      • 2014-10-16
      • 1970-01-01
      相关资源
      最近更新 更多