我試圖改編一個代碼來更改單個單詞的顏色,但我不知道如何。更改從腳本獲取的特定單詞的顏色
原代碼是
crypt_single_getPar = eval('(' + httpGet("https://api.cryptonator.com/api/ticker/" +
crypt_single_base_currency.match(/.*?\(([0-9a-z]+)\)/i)[1] + "-" + crypt_single_target_currency.match(/.*?\(([0-9a-z]+)\)/i)[1]) + ')');
和
if (crypt_single_getPar.success != false) {
if (crypt_single_getPar.ticker.price > 1)
crypt_single_price = Math.round(crypt_single_getPar.ticker.price * 100)/100;
else
crypt_single_price = crypt_single_getPar.ticker.price
var crypt_single_text_style = '<font style="color:#cc0000;"><b>↓</b></font>';
if (crypt_single_getPar.ticker.change >= 0) {
crypt_single_text_style = '<font style="color:#009900;"><b>↑</b></font>';
}
document.write('\
<div class="cryptonatorwidget" style="border-radius:4px;padding:10px;' + crypt_single_style + '">\
<div><font style="font-size:90%;">' + crypt_single_base_currency + '</font>\
<b>' + crypt_single_price + '</b> ' + crypt_single_target_currency.match(/.*?\(([0-9a-z]+)\)/i)[1] +'\
</div>');
結果是所有白色。 (我不能後圖像由於沒有最低口碑)
Decred(DCR)電流值] BTC
而且我試圖改變顏色像這樣
Decred( DCR)電流值] [綠色] BTC [綠色]
我想達到的效果
document.write('\
<div class="cryptonatorwidget" style="border-radius:4px;padding:10px;' + crypt_single_style + '">\
<div><font style="font-size:90%;">' + crypt_single_base_currency + '</font>\
<b>' + crypt_single_price + '</b> ' + <span style="color:#2ED7A2;">' + crypt_single_target_currency.match(/.*?\(([0-9a-z]+)\)/i)[1] + '</span>\
</div>');
但隨後迪出現在網頁上。
任何人都可以幫助我嗎?
謝謝。
PS:另外,有人告訴我不要在wordpress中使用eval(在這種情況下,文本小部件)。如何做到這一點沒有評估?
eval並非天生就是邪惡的,只是不安全,因爲很多人不知道他們在做什麼。如果你可以發佈一個你想做的複製例子,它會更容易幫助你。 –
Hello A. Lau 感謝您的幫助。 – Criptonauta
發現錯誤!感謝eval提示! – Criptonauta