Pereiti prie turinio

Comparenames javascript funkcija


Rekomenduojami pranešimai

Sveiki,

 

turiu va tokia programele ir jai dar trugsta javascript funkcijos, compareNames, kad vardai eitu abeceles tvarka. Tai gal kas galit pagelbet ir parodyt, kaip ji turetu buti iterpta i bendra programa.va ka turiu parases ir kokia comparenames funkcija turiu atskirai:

 

<html>
   <head>
       <style>
#pres td, #pres th { display: none; }
#pres td:nth-child(2), #pres th:nth-child(2) { display: table-cell; }
#pres td:nth-child(3), #pres th:nth-child(3) { display: table-cell; }
</style>
   </head>

   <body>
       <table id="pres" border="1">

       <?php
  /* $ch = curl_init//australianpolitics.com/united-states-of-america/president/list-of-presidents-of-the-united-states");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
$content = curl_exec($ch);
curl_close($ch);
      // echo $content; */
$html = file_get_contents("http://australianpolitics.com/united-states-of-america/president/list-of-presidents-of-the-united-states");





preg_match("/<tbody>[^>]*>(.*?)<\\/tbody>/is", $html, $match);
$html = strstr( $html, "<tbody" );
$html = substr( $html, 0, strpos( $html, "</tbody" ) - 1 );
echo $html;
Echo "<html>";
//if($matched) {
 //echo $match[1];

//} else {
// echo "No title tag found";
//}






       ?>
   </body>

</table>

</html>

 

cia javascript comparenames:

 <html>
<body>
<table id="pres" border="1">
</table>

<script type="text/javascript">

var presidents = [
   ["George Washington	","1789-1797"],
   ["John Adams	","1797-1801"],
   ["Thomas Jefferson	","1801-1809"],
   ["James Madison	","1809-1817"],
   ["James Monroe	","1817-1825"],
   ["John Quincy Adams	","1825-1829"],
   ["Andrew Jackson	","1829-1837"] ,
   ["Martin Van Buren	","1837-1841"],
   ["William H. Harrison	","1841"],
   ["John Tyler	","1841-1845"],
   ["James K. Polk	","1845-1849"],
   ["Zachary Taylor	","1849-1850 "],
   ["Millard Fillmore	","1850-1853"],
   ["Franklin Pierce	","1853-1857"],
   ["James Buchanan	","1857-1861"],
   ["Abraham Lincoln	","1861-1865 "],
   ["Andrew Johnson	","1865-1869"],
   ["Ulysses S. Grant	","1869-1877"],
   ["Rutherford B. Hayes	","1877-1881"],
   ["James A. Garfield	","1881 "],
   ["Chester A. Arthur	","1881-1885"],
   ["Grover Cleveland	","1885-1889"],
   ["Benjamin Harrison	","1889-1893"],
   ["Grover Cleveland	","1893-1897"],
   ["William McKinley	","1897-1901 "],
   ["Theodore Roosevelt	","1901-1909"],
   ["William Howard Taft	","1909-1913"],
   ["Woodrow Wilson	","1913-1921"],
   ["Warren G. Harding	","1921-1923 "],
   ["Calvin Coolidge	","1923-1929"],
   ["Herbert Hoover	","1929-1933"],
   ["Franklin D. Roosevelt	","1933-1945 "],
   ["Harry S Truman	","1945-1953"],
   ["Dwight D. Eisenhower	","1953-1961"],
   ["John F. Kennedy	","1961-1963 "],
   ["Lyndon B. Johnson	","1963-1969"],
   ["Richard M. Nixon	","1969-1974 "],
   ["Gerald R. Ford	","1974-1977"],
   ["James Earl Carter	","1977-1981"],
   ["Ronald Reagan	","1981-1989"],
   ["George Bush	","1989-1993"],
   ["William J. Clinton	","1993-2001"],
   ["George W. Bush ","2001-2009"],
   ["Barack H. Obama	","2009-"] 

];

function compareNames( p1, p2 )
{
   return p1[0] > p2[0] ? 1 : -1;
}
presidents.sort( compareNames );

var tbl = document.getElementById("pres");

for ( var p = 0; p < presidents.length; ++p )
{
   var pc = presidents[p];
   var tr = tbl.insertRow();
   var td1 = tr.insertCell();
   var td2 = tr.insertCell();
   td1.innerHTML = pc[0];
   td2.innerHTML = pc[1];
}
</script>
</body>
</html>

Tai kaip pirma programa sujungti su antra?

Nuoroda į pranešimą
Dalintis kituose puslapiuose

Tai gal dėl to ir klausiu koks būdas sujungimo šių dviejų funkcijų būt geriausias? :D

 

Tau ne šito reikia klausti... Sujungsi, panaudosi ir naudos bus lygiai 0, na nebent ta, kad darbas padarytas.

 

Patarčiau bent jau pasidomėti kas ką daro f-cijoje :)

Nuoroda į pranešimą
Dalintis kituose puslapiuose

Prisijunkite prie diskusijos

Jūs galite rašyti dabar, o registruotis vėliau. Jeigu turite paskyrą, prisijunkite dabar, kad rašytumėte iš savo paskyros.

Svečias
Parašykite atsakymą...

×   Įdėta kaip raiškusis tekstas.   Atkurti formatavimą

  Only 75 emoji are allowed.

×   Nuorodos turinys įdėtas automatiškai.   Rodyti kaip įprastą nuorodą

×   Jūsų anksčiau įrašytas turinys buvo atkurtas.   Išvalyti redaktorių

×   You cannot paste images directly. Upload or insert images from URL.

Įkraunama...
  • Dabar naršo   0 narių

    Nei vienas registruotas narys šiuo metu nežiūri šio puslapio.

×
×
  • Pasirinkite naujai kuriamo turinio tipą...