XML DOM lastChild ຜົນງານ:

ຄູ່ມືໂຕລະບົບ Document

ການອະທິບາຍ ແລະ ການນໍາໃຊ້:

ຜົນງານ lastChild ສາມາດຂໍ້ມູນຫນັງຄັ້ງທຳອິດຂອງໂຕເອກະສານ.

ວິທີການ:

documentObject.lastChild

ຄຳເຕືອນ ແລະ ຄວາມຄິດ:

ຄວາມຄິດ:Internet Explorer ຈະບໍ່ສົນໃຈຫົວຂໍ້ບັນຊີຍິງທີ່ສ້າງຂຶ້ນລະຫວ່າງຫົວຂໍ້ບັນຊີ (ອີງຕາມຫົວຂໍ້ບັນຊີຫົວໜ້າ), ແຕ່ Mozilla ຈະບໍ່ເຮັດແນວນັ້ນ. ດັ່ງນັ້ນ, ໃນຄັ້ງນີ້, ພວກເຮົາຈະໃຊ້ພະຍານເພື່ອກວດປະເພດຂອງຫົວຂໍ້ບັນຊີຍິງຫນັງຄັ້ງທຳອິດ.

ປະເພດຂອງຫົວຂໍ້ບັນຊີວິດຍິງ 1, ຖ້າຫົວຂໍ້ບັນຊີຍິງບໍ່ແມ່ນຫົວຂໍ້ບັນຊີຍິງຫນັງຄັ້ງທຳອິດ, ມັນຈະຍ້າຍໄປຫາຫົວຂໍ້ບັນຊີຍິງໃນຫນັງຄັ້ງໃຫມ່, ແລະສືບຕໍ່ກວດຫົວຂໍ້ບັນຊີຍິງນັ້ນວ່າຈະແມ່ນຫົວຂໍ້ບັນຊີຍິງຫນັງຄັ້ງທຳອິດ. ຂະບວນການຈະສືບຕໍ່ຈົນກວ່າຫົວຂໍ້ບັນຊີຍິງຫນັງຄັ້ງທຳອິດຖືກພົບ. ດ້ວຍວິທີນີ້, ພວກເຮົາສາມາດໄດ້ຮັບຜົນທີ່ຖືກຕ້ອງໃນ Internet Explorer ແລະ Mozilla.

Tip:For more information on the differences between XML DOM in IE and Mozilla browsers, please visit our DOM Browser Chapter.

Example

In all examples, we will use the XML file books.xml, and JavaScript function loadXMLDoc().

The following code snippet can display the node name and node type of the last child node of the document:

//Check if the last node is an element node
function get_lastchild(n)
{
var x=n.lastChild;
while (x.nodeType!=1)
{
x=x.previousSibling;
}
return x;
}
xmlDoc=loadXMLDoc("/example/xdom/books.xml");
var x=get_lastchild(xmlDoc);
document.write("Nodename: " + x.nodeName);
document.write(" (nodetype: " + x.nodeType + ")");

Output:

Nodename: bookstore (nodetype: 1)

ຄູ່ມືໂຕລະບົບ Document