[英]How I can use Buttons in a cordova application?
hi i want to build a cordova application with two buttons. 嗨,我想用两个按钮来构建一个cordova应用程序。
I have a plugin for show a toast in my android application. 我的Android应用程序中有一个用于显示吐司的插件。
If I click on the button i dont see a toast, but i execute the code without button i can see the toast. 如果我单击按钮,我看不到烤面包,但是我在没有按钮的情况下执行代码,我可以看到烤面包。
here is my index.html: 这是我的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>
Here is my index.js: 这是我的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();
验证JS是否已加载,并尝试调用app.setShortToast()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.