Javascript gets the maximum of of implementation code for the XML node

  • 2020-03-30 00:50:03
  • OfStack

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

The XML file,


<?xml version="1.0" encoding="utf-8"?>
<catalog>
<cd>
<ID>2</ID>
<title> The first 1 speak </title>
<mediaUrl>123</mediaUrl>
<htmlUrl>1.html</htmlUrl>
<orderNo>2</orderNo>
<StudyTimes>00:00:30</StudyTimes>
<Secondss times="30000">1.html</Secondss>
</cd>
<cd>
<ID>3</ID>
<title> The first 2 speak </title>
<mediaUrl>123</mediaUrl>
<htmlUrl>2.html</htmlUrl>
<orderNo>2</orderNo>
<StudyTimes>00:01:00</StudyTimes>
<Secondss times="60000">2.html</Secondss>
</cd>
<cd>
<ID>4</ID>
<title> The first 3 speak </title>
<mediaUrl>123</mediaUrl>
<htmlUrl>3.html</htmlUrl>
<orderNo>2</orderNo>
<StudyTimes>00:01:30</StudyTimes>
<Secondss times="90000">3.html</Secondss>
</cd>
</catalog>

Javascript:

MediaPlayer. Controls. CurrentPosition * 1000 to the current time


function times() {
//Define array array
var array =new Array();
//Define the xmldom protocol
var xmlDom =new ActiveXObject("Microsoft.XMLDOM");
xmlDom.async =false;
//Load XML file
xmlDom.load(id.value +"_imsmanifest.xml"); // jump 
try {
//Find all the Secondss
x = xmlDom.getElementsByTagName("Secondss");
// traverse 
for (i =0; i < x.length; i++) {
//Take times attribute
var s = x[i].getAttribute("times");
//If the attribute value is less than the MediaPlayer. Controls. CurrentPosition * 1000 is added to the array
if (s <= MediaPlayer.Controls.CurrentPosition *1000) {
array.push(s);
}
}
//Sorted array the array (array. The length - 1) is less than the MediaPlayer. Controls. CurrentPosition * 1000 the maximum inside
array.sort();
}


Related articles: