請原諒我,因爲我仍然是jQuery的新手,我比使用自己的代碼更容易使用其他代碼。 我的問題是關於這一行,具體爲:jQuery語法順序
$('r1.lastrow td.cell.c0').html(page).each(function(index, content) {
是在正確的語法順序HTML(網頁)?你怎麼看?
$.get('---------------/learn/mod/lesson/report.php?id='+lesson+'&action=reportdetail&userid='+userid+'&try='+lastAttempt, success: function(data) {
var page = $(data);
var lessonArray= new Array();
//loop through each element and grab the text
$('tr.r1.lastrow td.cell.c0').html(page).each(function(index, content) {
score=parseInt(content.substr(content.length - 1));
lessonArray[index]=score;
});
allLessonsArray[name]=lessonArray;
});
編輯:我有另一個問題,這次主要是由於我對jQuery的經驗不足。
userid= 17320;
courseid=4745;
allLessonsArray=script(userid, courseid);
function script(userid, courseid){
var lessonInTopicSectionArray= new Array();
lessonInTopicSectionArray['Floods, external']=376;
var allLessonsArray= new Array();
$.each(lessonInTopicSectionArray, function(name, lesson){
lastAttempt = 0;
url='----/learn/mod/lesson/report.php?id='+lesson+'&action=reportdetail&userid='+userid+'&try='+lastAttempt;
$.get(url, function(data) {
var page = $(data);
var lessonArray= new Array();
//loop through each element and grab the text
$('tr.r1.lastrow td.cell.c0').html(page).each(function(index, content) {
score=parseInt(content.substr(content.length - 1));
lessonArray[index]=score;
});
alert(name);
allLessonsArray[name]=lessonArray;
});
});
return allLessonsArray;
}
如何從前一個循環返回allLessonsArray,以便返回allLessonsArray?我不完全理解jQuery的面向對象方面,所以解釋會很好。
他們可能是在正確的順序或順序可能無關緊要。這取決於你想要做什麼。您在第二個代碼塊中缺少報價。 – kojiro 2012-08-10 16:21:26
感謝您的通知(代碼不是完整的代碼片段)。 我想在這種情況下做的是從先前打開的頁面中選擇每個r1.lastrow td.cell.c0,然後提取內容。 – 2012-08-10 16:29:07
@NathanLothamer'data'是服務器的響應(整個html頁面),你在尋找整個頁面放入'td.cell'嗎?如果不是,你需要過濾掉你需要的元素。 – 2012-08-10 16:36:08