<body onload="onLoad()">
<button onclick="onDeviceReady()">Click</button>
<div><output id="stuff"></output></div>
<script src="ttTracker.js"></script>
</body>
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
document.getElementById("stuff").value = "here";
}
// Cordova is loaded and it is now safe to make calls Cordova methods
function onDeviceReady() {
navigator.notification.prompt("Please enter your name", onPrompt,"Registration", ["Ok", "Exit"]);
document.getElementById("stuff").value = "harro";
}
function onPrompt(results) {
alert("You selected button number " + results.buttonIndex + " and entered " + results.input1);
}
单击计算机上iphone模拟器中的按钮时,不会弹出提示框。一直在研究这个问题。设备就绪无法正常工作?请帮忙!谢谢!
答案 0 :(得分:0)
您没有将您的javascript代码放在Button btn = new Button();
btn.setText("Close");
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.exit(0);
}
});
?
答案 1 :(得分:0)
仅在deviceready
事件被触发后才添加load
侦听器,此时deviceready
事件已被触发。
试试这个:
<body>
<button onclick="onClickButton()">Click</button>
<div><output id="stuff"></output></div>
<script src="ttTracker.js"></script>
<script>
function onClickButton() {
navigator.notification.prompt("Please enter your name", onPrompt,"Registration", ["Ok", "Exit"]);
}
function onDeviceReady() {
document.getElementById("stuff").value = "harro";
}
document.addEventListener("deviceready", onDeviceReady, false);
function onPrompt(results) {
alert("You selected button number " + results.buttonIndex + " and entered " + results.input1);
}
</script>
</body>