从奥鹏一个答案提取页面 看jquery知识点
http://oldlearn.open.com.cn/OEMSExercise/HomeworkReview.aspx?HomeworkId=9c034488-0a3d-4b9d-a6cc-e42200459094&S&S&S&S&S&S&S&S&S&S&S&S&S&S&S&S&S&S&S&S&S&S&SectionIndex=1
想要提取页面上 选定答案的 并且打印到控制台
var answer=''; $('.TestItemBody').each(function(i){var txt=$(this).children(":last").text().match(/([A-Z]+)/g)[0]; answer+=txt; if((i+1)%5==0)answer+=' '; if($(this).parent().attr('id')=='divSection2')answer+=' '; });console.log(answer); var answer=''; $('.TestItemBody').each(function(i){ $(this).children().find("input").each(function(j){ if($(this).attr("checked"))console.log(i+" "+j+" "+$(this).attr("checked",true)[0].nextSibling.nodeValue);}) }) var answer=''; $('.TestItemBody').each(function(i){ $(this).children().find("input").each(function(j){ if($(this).attr("checked")){ var ans= $(this).attr("checked",true)[0].nextSibling.nodeValue.match(/([A-Z]+)/g)[0]; answer+=ans; } }); if((i+1)%5==0)answer+=' '; if($(".myCourseNavOver").text().lastIndexOf("多选题")!=-1)answer+=' '; }); console.log(answer); var answer = ''; $('.TestItemBody').each(function(i) { $(this).children().find("input").each(function(j) { if ($(this).attr("checked")) { var ans = $(this).attr("checked", true)[0].nextSibling.nodeValue.match(/([A-Z]+)/g)[0]; answer += ans; } }); if ((i + 1) % 5 == 0) answer += ' '; if ($(".myCourseNavOver").text().lastIndexOf("多选题") != -1) answer += ' '; }); console.log(answer); // jquery 方式获取radio的 文本值 $(this).attr("checked", true)[0].nextSibling.nodeValue; //只取 字母部分 $(this).attr("checked", true)[0].nextSibling.nodeValue.match(/([A-Z]+)/g)[0]; var answer=''; $('.TestItemBody').each(function(i){ $(this).children().find("input").each(function(j){ if($(this).attr("checked")){ var ans= $(this).attr("checked",true)[0].nextSibling.nodeValue.match(/([A-Z]+)/g)[0]; answer+=ans; } }); if((i+1)%5==0)answer+=' '; if($(".myCourseNavOver").text().lastIndexOf("多选题")!=-1)answer+=' '; }); console.log(answer); 多选题: ABC ABCD AB ABC CD ABC AD AB C BCD var answer=''; $('.TestItemBody').each(function(i){ $(this).children().find("input").each(function(j){ if($(this).attr("checked")){ var ans= $(this).attr("checked",true)[0].nextSibling.nodeValue.match(/([A-Z]+)/g)[0]; answer+=ans; } }); if((i+1)%5==0)answer+=' '; if($(".myCourseNavOver").text().lastIndexOf("多选题")!=-1)answer+=' '; }); console.log(answer); 单选题: BBAAA BAABA