请原谅我,因为我仍然是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