第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

元素識別中的隨機(jī)背景梯度函數(shù)問題

元素識別中的隨機(jī)背景梯度函數(shù)問題

BIG陽 2022-12-29 16:36:43
我開發(fā)了一個程序,我的第一個函數(shù) (GetValue()) 從我創(chuàng)建的顏色數(shù)組中選擇兩種顏色。這些顏色存儲在變量中 - randomColor1 和 randomColor2接下來,我創(chuàng)建了一個函數(shù)來制作我的背景漸變。為此,我調(diào)用元素(randomColor1 和 randomColor2)。但它不工作并顯示錯誤為未定義(randomColor1 和 randomColor2)并且我的背景顏色沒有改變。最后,我合并了上述兩個功能。請幫我修復(fù)我的代碼。我不明白我做錯了什么。我是菜鳥。這是我的代碼function GetValue() {  var myarray = new Array( "#ff0000", "#ffe100", "#95ff00", "#2c8d94", "#ad6428", "#28ad9d");  var randomColor1 = myarray.splice(    Math.floor(Math.random() * myarray.length),1)[0];  var randomColor2 = myarray.splice(    Math.floor(Math.random() * myarray.length),1)[0];  document.getElementById("message").innerHTML = randomColor1 + randomColor2;}var styles = ["to right", "to bottom right", "-90deg"];function applyChanges(randomColor1, randomColor2) {  var randomColor1 = GetValue();  var randomColor2 = GetValue();  var bg = "";  var style = Math.floor(Math.random() * styles.length);  bg = "linear-gradient(" + styles[style] + "," + randomColor1 + "," + randomColor2 + ")";  $("body").css("background", bg);  $("#myInput").text(bg);}function changeBg() {  var randomColor1 = GetValue();  var randomColor2 = GetValue();  applyChanges(randomColor1, randomColor2);}
查看完整描述

2 回答

?
慕婉清6462132

TA貢獻(xiàn)1804條經(jīng)驗 獲得超2個贊

沒有返回任何內(nèi)容,因此修復(fù)它的GetValue()一種方法是返回兩種顏色,然后按如下所示分配它們:


function GetValue() {

    var myarray = new Array("#ff0000", "#ffe100", "#95ff00", "#2c8d94", "#ad6428", "#28ad9d");

    var randomColor1 = myarray.splice(

        Math.floor(Math.random() * myarray.length), 1)[0];

    var randomColor2 = myarray.splice(

        Math.floor(Math.random() * myarray.length), 1)[0];


    /* Return like this*/

    return [randomColor1, randomColor2];

}


并將 changeBG() 更改為

function changeBg() {

    /* Get colors like this since they are returned like this*/

    var [randomColor1, randomColor2] = GetValue();

    /* Log it to see what colors they are*/

    console.log(randomColor1, randomColor2);

    /* Call the apply method*/

    applyChanges(randomColor1, randomColor2);

}


查看完整回答
反對 回復(fù) 2022-12-29
?
狐的傳說

TA貢獻(xiàn)1804條經(jīng)驗 獲得超3個贊

您必須簡化您的 GetValue 函數(shù):只需創(chuàng)建 1 個值并返回它。其余的都可以。


讓我們在這里試試:


function GetValue() {

  var myarray = new Array( "#ff0000", "#ffe100", "#95ff00", "#2c8d94", "#ad6428", "#28ad9d");

  return myarray.splice(Math.floor(Math.random() * myarray.length),1)[0];

}



var styles = ["to right", "to bottom right", "-90deg"];



function applyChanges(randomColor1, randomColor2) {

  var randomColor1 = GetValue();

  var randomColor2 = GetValue();

  var bg = "";

  var style = Math.floor(Math.random() * styles.length);

  bg = "linear-gradient(" + styles[style] + "," + randomColor1 + "," + randomColor2 + ")";

  $("body").css("background", bg);

  $("#myInput").text(bg);

}


function changeBg() {

  var randomColor1 = GetValue();

  var randomColor2 = GetValue();

  applyChanges(randomColor1, randomColor2);

}


document.getElementById('btn').addEventListener('click', function() {

    changeBg();

});

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div id='message'></div>

<input id='myInput'>

<button id='btn'>Click me</button>


查看完整回答
反對 回復(fù) 2022-12-29
  • 2 回答
  • 0 關(guān)注
  • 98 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號