我想在Javascript中調用一個函數,但它不工作。JavaScript不能在科爾多瓦與溫泉
我沒有在溫泉網站和Google上找到任何參考。
任何人都可以告訴我在JavaScript中調用函數的精確步驟是什麼?
我需要在index.js文件中定義函數還是可以在腳本標記中的同一個文件中寫入函數?
我使用溫泉2
我也曾詢問過關於 JQuery但沒有解決辦法還沒有類似的問題。
p1.html
<body onload="onLoad()">
<ons-page>
<ons-button id="demo" onclick="printMsg()">Click Me</ons-button>
</ons-page>
index.js
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
document.getElementById('demo').addEventListener("click", printMsg,
false);
document.getElementById('btnNext').addEventListener("click",
callNextPage, false);
document.addEventListener("pause", onPause, false);
document.addEventListener("resume", onResume, false);
document.addEventListener("menubutton", onMenuKeyDown, false);
}
function printMsg() {
ons.notification.alert('Hello'):
//alert('hello');
//document.addEventListener("deviceready", onDeviceReady, false);
}
輸出錯誤消息:
「未捕獲的ReferenceError:printMsg沒有定義」,來源: file:///android_asset/www/index.html
編輯:
我已經上傳我的項目在FileDropper
刪除內聯事件處理程序,以便按鈕只是...'<插件按鈕ID =「演示」>點擊我'。這不應該解決它,但你不需要,因爲你是在設備準備功能分配處理程序 – Archer
@Archer我試過它不工作 –