ようこそフォーラムへ! 今日私は言語Javascript/html/css/phpで少しコードを作成したかったのですが、問題が残っていました。 (私はどこでもこの問題を探しましたが、結果はありません)Javascript/Html/CSSランダム背景画像と2つのjavascript配列の単語
私の問題は=>私のjsファイルに2つの配列があります。最初にディレクトリから画像を保存し、2番目の画像はMath()でランダムに選択したい単語を保存します。#indexes 私のコードですべてを読むことができます。私は彼らにコメントした。 jQueryを使って
window.onload = chooseGame;
var cGamePic = new Array("football.jpg","baseball.jpg");
var cGameName = new Array("football","baseball");
function chooseGame;
\t var rnd_num = Math.floor(Math.random() * cGamePic.length);
\t document.getElementById("comp1Game").src = cGamePic(rnd_num);
document.getElementById("??").?? = cGameName(rnd_num);
<!DOCTYPE html>
<html>
\t <head>
\t \t <title>Random pics</title>
\t \t <script src="rnd.js"></script>
\t \t <link rel="stylesheet" type="text/css" href="style.css">
\t </head>
\t <body>
\t \t <div id="container1">
\t \t \t <h1>Some text 1</h1>
\t \t \t <!--The next line will be displayed,but not randomly.
\t \t \t And I want it to the left-side of screen,as background image.
\t \t \t Like: the text "Some text 1" will be displayed in the random selected image.
\t \t \t (The some text 1 is selected randomly too,as "football")
\t \t \t -->
\t \t \t \t <img src="res/images/football.jpg" id="comp1Game" alt="Compare1">
\t \t </div>
\t
\t \t <div id="container2">
\t \t \t <h1>Some text 2</h1>
\t \t \t <!-- The future container to see the 2nd selected image & word in it (right side of screen)
\t \t \t Like,if js select number 6,the word and image will be "baseball" and "baseball.jpg"
\t \t \t Shortly,I want to do it.
\t \t \t -->
\t \t </div>
\t </body>
</html>
だからそれは何ですか?私は実際に "var name = pic.replace"という行を理解していません。 rnd.jsはまだ同じで、私はそれが必要ですか?とにかく、ありがとう! :) – LeFizzy
"var name = pic.replace"では、パスからベース名を抽出できるので、cGameName配列は不要です。 rnd.jsを使用する必要はありません。 ;) – polamoros