Javascript 无法调用未获取page.matches OnSenUi的函数
项目附件 我已经浪费了一辈子的时间来解决这个问题。我正处于混合应用开发的初级阶段,这件事正在伤害我。 我在Cordova工作,使用OnSen UI作为开发应用程序的框架。 我的JavaScrip和jQuery一切正常,但我无法从onClick方法调用函数 我想要的是,在里面: ,, 我有一个id为divFtechHere的div 我想找到它并打电话:Javascript 无法调用未获取page.matches OnSenUi的函数,javascript,jquery,cordova,onsen-ui,Javascript,Jquery,Cordova,Onsen Ui,项目附件 我已经浪费了一辈子的时间来解决这个问题。我正处于混合应用开发的初级阶段,这件事正在伤害我。 我在Cordova工作,使用OnSen UI作为开发应用程序的框架。 我的JavaScrip和jQuery一切正常,但我无法从onClick方法调用函数 我想要的是,在里面: ,, 我有一个id为divFtechHere的div 我想找到它并打电话: if (page.matches('#fetchPage.html')) { page.querySelector('#divFtechHere'
if (page.matches('#fetchPage.html')) {
page.querySelector('#divFtechHere').onclick = function() {
console.log ("list Item Clicked!");
alert('Now clicked');
};
} // page.matches('#fetchPage.html')
但这是行不通的
最终,,
我想要实现的是:
当我想点击myListElement时,它有一个项目列表,它会返回ID给我,这样我就可以从Web服务器获取更多信息。
请帮我解决这个问题。如果你能帮我修复我的整个文档,我会很高兴的。addEventListener'init',函数,即使我认为我在那里也做错了什么。
多谢各位
这是我的全部代码:
index.html
myJs.js
哇
我只是编辑一下:
if (page.matches('#fetchPage.html')) {
page.querySelector('#divFtechHere').onclick = function() {
console.log ("list Item Clicked!");
alert('Now clicked');
};
} // page.matches('#fetchPage.html')
到
现在它正在工作
方法现在正在调用,Yep:D相关:
$(document).ready(function() {
console.log("Code Loaded");
// $('#divFtechHere').onclick = function() {
// //event.preventDefault();
// console.log ("list Item Clicked!");
// alert('Now clicked');
// };
document.addEventListener('init', function (event) {
var page = event.target;
if (page.matches('#helloworld-page')) {
page.querySelector('#btnSignIn').onclick = function() {
addFunction();
};
page.querySelector('#btnClickMe').onclick = function() {
//ons.notification.alert('Hello Click Me!');
fn.load('fetchPage.html');
fetchFunction();
//alert("btnClickMee");
};
// Another Tab Item
// Uncomment this bellow line to see list of items.
//$("#ons-list-fetch").click(fetchFunction);
// When clicked on List Item index may be pop up
$("#myListElement").click(listClicked);
} // eof page.matches('#helloworld-page
// Another Page
if (page.matches('#fetchPage2.html')) {
page.querySelector('#divFtechHere').onclick = function() {
console.log ("list Item Clicked!");
alert('Now clicked');
};
} // eof page.matches('#fetchPage2.html')
});
// For Menu Icon
window.fn = {};
window.fn.open = function() {
var menu = document.getElementById('menu');
menu.open();
};
window.fn.load = function(page) {
var content = document.getElementById('content');
var menu = document.getElementById('menu');
content.load(page)
.then(menu.close.bind(menu));
}; // eof Menu Icon
function listClicked(){
ons.notification.alert("You click on: ");
alert("You click on: ");
}
function addFunction(){
var user_name1 = $('#username').val();
var user_age1 = $('#password').val();
console.log("testFunc is invoked");
console.log("user_name: " + user_name1 + " user_age: " + user_age1);
$.post({
type: 'POST',
url: "add.php?user_name=" + user_name1 + "&user_age=" + user_age1,
timeout: 5000,
success:function(result){
console.log("Added: " + result);
ons.notification.alert("Success: " + result);
//$("#div1").html(result);
console.log("Success");
},
error: function(err){
ons.notification.alert("Error: " + err.status + ", " + err.statusText);
console.log("Error: " + err);
// console.log(err.status);
// console.log(err.statusText);
// $("#div1").text(err.responseText);
}
});
}
function fetchFunction(){
//fn.load('fetchPage.html');
console.log("fetchFunction is invoked");
var header = "<ons-list-header>My Inset List</ons-list-header>";
$.post({
type: 'POST',
url: "fetch.php",
success:function(result){
timeout: 5000,
$("#myListElement").html(header);
$("#myListElement").append(result);
// $('.center').onclick = function () {
// //listClicked1();
// alert(8);
// };
//console.log("Fetched: " + result);
//ons.notification.alert("Success: " + result);
//$("#div1").html(result);
console.log("Success");
},
error: function(err){
ons.notification.alert("Error: " + err.status + ", " + err.statusText);
console.log("Error: " + err);
// console.log(err.status);
// console.log(err.statusText);
//$("#div1").text(err.responseText);
}
});
}
});
//var login = function() {
// var username = document.getElementById('username').value;
// var password = document.getElementById('password').value;
//
// if (username === 'asd' && password === 'asd') {
// ons.notification.alert('Congratulations!');
// }
// else {
// ons.notification.alert('Incorrect username or password.');
// }
//};
if (page.matches('#fetchPage.html')) {
page.querySelector('#divFtechHere').onclick = function() {
console.log ("list Item Clicked!");
alert('Now clicked');
};
} // page.matches('#fetchPage.html')
if (event.target = "fetchPage.html") {
$("#divFtechHere").click(function () {
alert("Div Clicked");
});
}