你能帮忙解决一下吗? [英] can you help how to figure it out

查看:72
本文介绍了你能帮忙解决一下吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您的任务是获取以下html文件并实现获取XML文件(events.xml)所需的代码,从XML文档中提取事件,最后在使用DOM方法创建的表中显示提取的信息。

创建表格后,您需要将其插入下面显示的

Your assignment is to take the following html file and implement the code necessary to take the XML file (events.xml), extract the events from the XML document and finally display the extracted information in a table you will create using DOM methods.
Once you’ve created the table, you will need to insert it inside the

(id =cal)内。仅使用幻灯片中显示的DOM方法。不要使用innerHTML或类似的方法。

(id= "cal") shown below. Use only the DOM methods that appear in my slides. Do not use innerHTML or similar methods.
<html>
 <head>
<title>Handling Events</title>
 </head>
<body>
 <div id=""cal""></div>
 <script src="process+events.js"></script>
 <script>
var oReq = new XMLHttpRequest();
oReq.addEventListener("load", processEvents);
oReq.open("GET", "http://pubpages.unh.edu/~jlw/771/events.xml");
oReq.send();
 </script>
 </body>
</html>



您会注意到XML文件中的每个事件都是空的< ;映射>元件。当你提取事件信息时,可以忽略那个

元素(但是不要从XML文件中删除它们,只需编写代码来忽略它们)。



进程+ event.js文件中的JavaScript应包含以下函数:



事件的构造函数 - XML文件中提取的日期将是一个字符串,使用新的Date(datetime)将其转换为日期对象。另外两个属性将保留字符串。



一个名为processEvents的函数,它从XML文件中提取事件,对它们进行排序

,最后创建用于显示它们的表。



一个名为collectEvents的函数,它从XML文件中提取事件并返回

一个已排序的数组事件对象。



一个名为compareDates的函数,用于按datetime对事件数组进行排序。 Google for Array.prototype.sort有关如何编写

compareDates函数的更多信息。


You will notice that the each event in the XML file has an empty <map> element. That
element can be ignored when you extract the event information (but don’t remove them
from the XML file, just write code to ignore them).

The JavaScript in the process+event.js file should include the following functions:

A constructor for events – the extracted date from the XML file will be a string, use new Date(datetime) to convert it to a date object. The two other properties will stay strings.

A function called processEvents which extracts the events from the XML file, sorts
them, and finally creates the table used to display them.

A function called collectEvents that extracts the events from the XML file and returns
an array of sorted event objects.

A function called compareDates that is used to sort the events array by datetime. Google for Array.prototype.sort for more information about how to write the
compareDates function.





[更新]

我附加了代码..我无法显示最终表格。我不知道为什么?







[Update]
I am attaching the code..I am unable to display the final table. I don't know why?


function event( title,datetime,location)

{
     this.date=new Date(datetime);
     this.title=title;
     this.location=location;
}
function processEvents()
{
     var events;
     if(this.status==200&&this.responseXML!=null)
     {
          events=collectEvents();
     }

     var table=documnet.createElement("TABLE");
     var tableBody=document.createElement("tbody");
     var htmlbody=document.getElementsByTagName('div');
     for(var k1=0;k1<events.length;k1++) {="" var="" tblrow="document.createElement("tr");" col1="document.createElement("td");" col2="document.createElement("td");" col3="document.createElement("td");" col1.appendchild(events[k1].datetime);="" col2.appendchild(events[k1].title);="" col3.appendchild(events[k1].location);="" tblrow.appendchild(col1);="" tblrow.appendchild(col2);="" tblrow.appendchild(col3);="" tablebody.appendchild(tblrow);="" }="" table.appendchild(tablebody);="" htmlbody.appendchild(table);=""  ="" function="" collectevents()="" eventlist="new" array();="" if(this.status="=200&&this.responseXML!=null)" xmlelem="this.responseXML;" title1="xmlElem.getElementsByTagName("title");" datetime1="xmlElem.getElementsByTagName("datetime");" location1="xmlElem.getElementsByTagName("location");" len="title1.length;" for(var="" k1="0;k1<len;k1++)" eventlist.push(new="" event(title1[k1].childnodes[0].nodevalue,datetime1[k1].childnodes[0].nodevalue,location1[k1].childnodes[0].nodevalue));="" neweventlist="eventList.sort(compareDates);" comparedates(date1,date2)="" return="" date1-date2;="" }<="" div="">	<div id="EditDialogPlaceholder"></div>	<div id="ReplyDialogPlaceholder"></div></events.length;k1++)>

推荐答案

< b>家庭作业。



你的帖子上写着 Google for Array.prototype.sort ,但是你呢? br $> b $ b

首先,根本不是问题。

其次,你到目前为止尝试了什么?

三,如果你做到了,你在哪里卡住?错误是什么?有什么例外吗?



请阅读代码项目快速解答常见问题解答 [ ^ ]



-KR
Homework.

Your post says, "Google for Array.prototype.sort", but did you ?

First, not a question at all.
Second, you tried anything so far ?
Third, if you did, where do you stuck ? What's the error ? Any exception ?

Please read this Code Project Quick Answers FAQ[^]

-KR


这篇关于你能帮忙解决一下吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆