Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php, js]Losowy skrypt
Forum PHP.pl > Forum > Przedszkole
inOs
Witajcie, szukam takiego skryptu, co wyświetlałby losowo, link i pod nim obrazek, znalazłem na losowe obrazki, i text tez, ale nie wiem jak to złączyć... można zrobić coś takiego aby do skryptu wpisać dało sie byle co? Cos w stylu, aby bylo miejsce, w skrypcie na to co ma sie tam wyświetlić i mógłby być to np html coś w stylu
"<strong>Company Name</strong><a href="http://www.styleshout.com/">styleshout</a>"
Dałoby sie?
Tu macie skrypty
radom image smile.gif


CODE


<html>
<head>
<title>Random Image with Link</title>
</head>
<body>
<script language="javascript">
<!--
var b1dis = "<a href=\"";
var bdis = "\"><img src=\"";
var edis = " width=\"110\" height=\"100\" alt=\"some text\" border=\"0\"></a>";
var rnumb = "";
var img = "";

rnumb += Math.floor(Math.random()*3);
img = rnumb;

if (img == "0") {
document.write(b1dis+ "page1.html" +bdis+ "images/p1.gif\"" +edis);
}

if (img == "1") {
document.write(b1dis+ "page2.html" +bdis+ "images/p2.gif\"" +edis);
}

if (img == "2") {
document.write(b1dis+ "page3.html" +bdis+ "images/p3.gif\"" +edis);
}

// -->
</script>
</body>
</html>

Random Image with Link








Radom text smile.gif
CODE

<script LANGUAGE="JavaScript" TYPE="text/javascript">


var sc = 10; // Number of alternative strings
var s = new Array(sc); // Array to hold alternative strings



s[0] = "She won't live, of course. But then again ... who does?";
s[1] = "I seem to be having tremendous difficulty with my lifestyle.";
s[2] = "Frog blast the vent core!";
s[3] = "Pizza is a lot like sex. When it's good, it's really good. " +
"When it's bad, it's still pretty good.";
s[4] = "unix soit qui mal y pense";
s[5] = "Wriggling grunion in your slipstream";
s[6] = "I'm shocked to hear it. The Hyperdyne 400 series always " +
"were a bit twitchy.";
s[7] = "I have the greatest enthusiasm for our mission, Dave.";
s[8] = "Do not taunt Happy Fun Ball.";
s[9] = "Do not look into laser with remaining good eye.";



function pickRandom(range) {
if (Math.random)
return Math.round(Math.random() * (range-1));
else {
var now = new Date();
return (now.getTime() / 1000) % range;
}
}



var choice = pickRandom(sc);
document.writeln("<TABLE WIDTH=460 ALIGN=CENTER><TR><TD>" +
"<BLOCKQUOTE><BIG><B>" + s[choice] +
"<" + "/B><" + "/BIG><" + "/BLOCKQUOTE>" +
"<" + "/TD><" + "/TR><" + "/TABLE>");

</SCRIPT>


Pozdrawiam i proszę o pomoc, może Wam sie wydawać ze o głupoty sie pytam, ale jestem w tym ciemny :C Pozdrawiam
.radex
Weź mi ten javascript tongue.gif

O ile dobrze zrozumiałem problem najłatwiej jest dodać wszystko do jakiejś tablicy, np:

  1. <?php
  2. $linki[] = array('screenshot.png' , 'something.net');
  3.  
  4. $linki[] = array('costaminnego.jpg' , 'google.com');
  5. ?>


a następnie wyświetlić:

  1. <?php
  2. $rand = rand(0, (count($linki)-1));
  3.  
  4. echo '<img src="img/'.$linki[$rand][0].'" alt="'.$linki[$rand][1].'"><a href="http://'.$linki[$rand][1].'">'.$linki[$rand][1].</a>;
  5. ?>
Cysiaczek
Popraw proszę tytuł topiku na zgodny z zasadami forum Przedszkole, dodaj bbcode oraz opisz, co chcesz zrobić, bo z Twojego posta niewiele wynika
skowron-line
to ja moze dodam link
http://pl2.php.net/manual/en/function.shuffle.php
inOs
Chodzi mi o to, aby można było zrobić takie coś, jak tutaj http://www.funner.pl/ po prawej stronie, albo tutaj http://www.maxmix.pl/ , porostu, losowe filmiki...
Kod
<script type="text/javascript">
    // <![CDATA[
    Array.prototype.random = function(limit)
    {
        if (typeof limit == 'undefined' || limit < 0) limit = 1;
        else if (!limit) limit = this.length;
        for (var i = 0, source = this, target = new Array(), n = source.length; i < limit && n > 0; i++)
        {
            do { var index = Math.random(); } while (index == 1);
            index = Math.floor(index * n);
            target.push(source[index]);
            source[index] = source[--n];
        }
        return target;
    }
    
    document.write(new Array(
    // Tu wpisz kolejne elementy:
    
    '<a href="index.html">
                    <img alt="" src="mini/inevofda.jpg" width="93" height="70" style="float: left" /></a><b><a href="index.html">Amazing
                    Street Drummer</a></b><br />
                    El videos mas famoso del youtube</div>
                <p class="style22" style="width: 265px; height: 8px">
                <img alt="" src="pod.gif" width="251" height="2" /></p>
    ',
    '<div style="height: 79px; width: 254px;">
                    <a href="index.html">
                    <img alt="" src="mini/huacyho.jpg" width="94" height="68" style="float: left" /></a><b><a href="index.html">Accidentes
                    y hostias</a></b><br />
                    Uno de los videos de los accidentes mas graciosos</div>
                <p class="style22" style="width: 265px; height: 8px">
                <img alt="" src="pod.gif" width="251" height="2" /></p>
    ',
    '    <div style="height: 79px; width: 254px;">
                    <a href="index.html">
                    <img alt="" src="mini/huacyho.jpg" width="94" height="68" style="float: left" /></a><b><a href="index.html">Accidentes
                    y hostias</a></b><br />
                    Uno de los videos de los accidentes mas graciosos</div>
                <p class="style22" style="width: 265px; height: 8px">
                <img alt="" src="pod.gif" width="251" height="2" /></p>
    '
    
    ).random().join(''));
    // ]]>
    </script>



Cos takiego udało mi sie wykombinować, ale nie działa, dlaczego?
Kod
<script>
function nazwa_funkcji() {
document.getElementById('blok').innerHTML = 'to co ma byc w bloku';
}</script>
<a href=costam onClick="nazwa_funkcji()"> zobacz</a>
<div id="blok"> Zawartosc bloku</div>


Znalazłem tez to, nie wiem sam dokładnie jak to działa...
.radex
Nie rozumiem, ale dlaczego chcesz koniecznie to zrobić w JavaScript? Co do twojego przykładu, to zobacz w kursie, czy nie zrobiłeś literówki - nie jestem zbyt dobry w JavaScript, który rozróżnia wielkość liter, np. GetElementByID i getElementById to inne funkcje...
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.