Home > Web Front-end > JS Tutorial > body text

JavaScript gets the maximum value of xml node (implementation code)_javascript skills

WBOY
Release: 2016-05-16 17:09:51
Original
1097 people have browsed it

Suppose the current time is now 7000 milliseconds. When the time is 3000--6000, the value of 3000 is taken. When 6000--9000, the value of 6000 is taken, that is, the maximum value in xml that is less than the current time is taken

xml file,

Copy code The code is as follows:




2
Lecture 1< ;/title><br><mediaUrl>123</mediaUrl><br><htmlUrl>1.html</htmlUrl><br><orderNo>2</orderNo><br><StudyTimes>00 :00:30</StudyTimes><br><Secondss times="30000">1.html</Secondss><br></cd><br><cd><br><ID> 3</ID><br><title>Lecture 2
123
2.html
< ;orderNo>2
00:01:00
2.html


4
Lecture 3
123
3.html
2
00:01:30
3.html



javascript:

MediaPlayer.Controls.CurrentPosition * 1000 is the current time

Copy code The code is as follows:

function times() {
//Define array array
var array =new Array();
//Define xmldom protocol
var xmlDom =new ActiveXObject("Microsoft.XMLDOM");
xmlDom.async =false;
//Load xml file
xmlDom.load(id.value "_imsmanifest.xml"); //Jump
try {
//Find all Secondss
x = xmlDom.getElementsByTagName("Secondss");
//Traverse
for (i =0; i < x.length; i) {
//Get the times attribute
var s = x[i].getAttribute("times");
//If the attribute value is less than MediaPlayer.Controls.CurrentPosition * 1000, add it to the array
if (s <= MediaPlayer.Controls. CurrentPosition *1000) {
array.push(s);
}
}
//Sort array At this time, array[array.length - 1] is smaller than MediaPlayer.Controls.CurrentPosition * 1000 The maximum value of
array.sort();
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template