Autor | Zpráva | ||
---|---|---|---|
Harry Potter Profil * |
#1 · Zasláno: 21. 8. 2014, 11:25:31
cau, chcem ze ked kliknem na button, zobrazi sa nahodny div, funguje to, ale iba raz.
potreboval by som aby sa po kliku na button opakovane zobrazil nahodny div... poradite mi ako na to? dakujem. <script> jQuery(document).ready(function($){ var $showStuff = new Array();// lets make an array to represent the users stuff var i=0; while (i<=11) {// you could just as easily use a for loop here if($('.showStuff'+i).length){// we test to see if a .showStuff+ object exists $showStuff[i] = $('.showStuff'+i);// we assign it an array value } i++; } $('button').click(function() { $showStuff[showRandom].show(); }); // And then you want to generate the randomness with Math var showRandom = Math.floor(Math.random()*$showStuff.length); // Hide all the divs with the common class $('.hideStuff').hide(); }); </script> <button>Randomize</button> <div class="hideStuff showStuff1"> this is the FIRST div </div> <div class="hideStuff showStuff2"> this is the SECOND div </div> <div class="hideStuff showStuff3"> this is the THIRD div </div> <div class="hideStuff showStuff4"> this is the FOURTH div </div> |
||
lionel messi Profil |
#2 · Zasláno: 21. 8. 2014, 11:29:11
Harry Potter:
Možno pomôže: Výpis náhodného textu |
||
Harry Potter Profil * |
#3 · Zasláno: 21. 8. 2014, 12:41:28
este som nasiel aj toto:
function loadExternalHTMLPage(pages) { $('#contentArea').load(pages[Math.floor(Math.random() * pages.length]); } // This replaces body.onload $(document).ready(function(){ var pagesToDisplay = ['good.htm', 'evil.htm']; loadExternalHTMLPage(pagesToDisplay); }); vyzera to jednoducho ale nefungovalo to. som vyvoril button a dal ze onClick="loadExternalHTMLPage('blabla.html', 'druhe.html')" |
||
Časová prodleva: 10 let
|
0