次のコードを使用してテキストの色を変更したいと思いますが、.each
が呼び出されたときにエラー:Uncaught syntax: unexpected string
が表示されます。私は何が間違っているのか分かりません。jqueryを使用してテキストを擬似ランダム色に変更します
function random_rgb() {
colors = ['8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
r = colors.eq(Math.floor(Math.random * 8));
g = colors.eq(Math.floor(Math.random * 8));
b = colors.eq(Math.floor(Math.random * 8));
return '#' + r + g + b;
};
$(document).ready({
$("span.number").each(function(){
this.style.color = random_rgb();
});
});
UPDATE
私はhttps://jsfiddle.net/yrnqr566/
色は黒たびにアップになります(私はこのアプリ/ W素晴らしいではありませんよ私を許して)jsfiddleを作成しました。
あなたのHTMLはどんな感じでしょうか?このエラーを誇示するためのフィドルを手に入れましたか? – Novocaine
更新をご覧ください。 – tidelake
'Math.random'は関数で、' Math.random() 'を呼び出すには括弧を使う必要があります。 –