2011-02-04 4 views
0
<SCRIPT LANGUAGE="JavaScript"> 
<!-- Begin 
function go_to(Random link) { 
window.location=Random link; 
} 
function rand_link() { 
var a; 
a = 1+Math.round(Math.random()*2); // a = random number between 1-3 
if (a==m1) go_to("Cape Fear"); 
if (a==m2) go_to("The Good, the Bad and the Ugly"); 
if (a==m3) go_to("The Omen"); 
} 
// End --> 
</SCRIPT> 

<BODY> 

<FORM NAME="myForm"> 
<SELECT NAME="mylist" onChange="disp_text()"> 
<OPTION VALUE="m1">Cape Fear 
<OPTION VALUE="m2">The Good, the Bad and the Ugly 
<OPTION VALUE="m3">The Omen 
<OPTION VALUE="m4">The Godfather 
<OPTION VALUE="m5">Forrest Gump 
</SELECT> 
<INPUT TYPE="button" NAME="myButton" VALUE="Random link" 
onClick="rand_link()"> 
</FORM> 
</body> 

je voudrais au hasarderreur de syntaxe ECMAScript aléatoire

<OPTION VALUE="m1">Cape Fear 
<OPTION VALUE="m2">The Good, the Bad and the Ugly 
<OPTION VALUE="m3">The Omen 
<OPTION VALUE="m4">The Godfather 
<OPTION VALUE="m5">Forrest Gump 

ci-dessus syntaxe comment puis-je corriger mon code? ma question est comment faire une liste aléatoire par le bouton @ _ @. J'ai essayé de modifier quelques temps :(

+1

Bonjour et bienvenue sur StackOverflow! S'il vous plaît modifier votre question l'ajout des points suivants peut vous apporter de meilleures réponses: 1. Qu'est-ce que vous essayez d'accomplir ("liste aléatoire par bouton" - ordre? sélectionner? supprimer? autre chose?)? 2. Qu'avez-vous essayé jusqu'à présent? 3. Quels résultats avez-vous obtenus? 4. En quoi cela diffère-t-il des résultats que vous attendiez? (veuillez être plus précis, cela ne va pas de soi dans l'état actuel de votre question) – Piskvor

Répondre

1

je fixe une partie du code pour vous. Puisque vous n'avez pas urls rediriger vers

<SCRIPT LANGUAGE="JavaScript"> 
<!-- 
function go_to(Random_link) { 
    alert(Random_link); 
} 

function rand_link() { 
    var a= "m"+(1+Math.round(Math.random()*2)); // a = random number between 1-3 
    if (a == "m1"){ 
    go_to("Cape Fear"); 
    } else if (a == "m2") { 
    go_to("The Good, the Bad and the Ugly"); 
    } else if (a == "m3"){ 
    go_to("The Omen"); 
    } 
} 
// End --> 
</SCRIPT> 

<BODY> 

<FORM NAME="myForm"> 
    <SELECT NAME="mylist" onChange="disp_text()"> 
    <OPTION VALUE="m1">Cape Fear</option> 
    <OPTION VALUE="m2">The Good, the Bad and the Ugly</option> 
    <OPTION VALUE="m3">The Omen</option> 
    <OPTION VALUE="m4">The Godfather</option> 
    <OPTION VALUE="m5">Forrest Gump</option> 
    </SELECT> 
    <INPUT TYPE="button" NAME="myButton" VALUE="Random link" onClick="rand_link()"> 
</FORM> 
</body> 
, je viens d'alerte utilisé, vous pouvez le corriger plus tard.

Comme vous pouvez le voir, vous ne commentiez pas "Commencer" dans votre texte original, vous ne fermiez pas non plus les options de votre liste déroulante, vous compariez a, un entier 1, 2 ou 3. avec un variable indéfinie m1, m2 et m3, au lieu de la chaîne "m1", "m2", ou "m3" J'ai aussi changé pour if autrement, a ne peut pas être à la fois "m3" et "m2" ou "m1".
J'aurais pu fournir une meilleure réponse si comme le commentaire original dit que vous étiez plus précis avec votre question.

+0

Pendant que vous y êtes, vous devez supprimer le commentaire ('') et l'attribut 'language'. – RoToRa

+0

yo réponse est fonction uniquement aleart: P
je veux fonctionner sur la liste ( )/* doit fonctionner, je ne avez pas besoin de bonus alerte */ – malaya

+2

Je n'ai aucune idée de ce que vous essayez de dire. –