2017-04-07 17 views
1

1つの単語の色を変更するコードを調整しようとしていますが、どうすればよいか分かりません。スクリプトから取得した特定の単語の色を変更する

元のコードは、結果は全て白色である

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>&darr;</b></font>'; 

if (crypt_single_getPar.ticker.change >= 0) { 
    crypt_single_text_style = '<font style="color:#009900;"><b>&uarr;</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なしでそれを行うには?

+0

evalは本質的に邪悪ではなく、多くの人が何をしているのか分からないので危険です。あなたがしたいことの複製された例を投稿することができれば、あなたを助けやすくなります。 –

+0

こんにちはA.Lau 私を助けてくれてありがとう。 – Criptonauta

+0

エラーを見つけました! eval tipありがとう! – Criptonauta

答えて

0

ラウ

ありがとうございました。

時間では、私はエラー^^

crypt_single_display_time = false; 
 

 
function httpGet(theUrl) 
 
{ 
 
    var xmlHttp = null; 
 

 
    xmlHttp = new XMLHttpRequest(); 
 
    xmlHttp.open("GET", theUrl, false); 
 
    xmlHttp.send(null); 
 
    return xmlHttp.responseText; 
 
} 
 

 
function FormatNumberLength(num, length) { 
 
    var r = "" + num; 
 
    while (r.length < length) { 
 
     r = "0" + r; 
 
    } 
 
    return r; 
 
} 
 

 
crypt_single_base_currency = typeof crypt_single_base_currency == "undefined" ? "Bitcoin (BTC)" : crypt_single_base_currency; 
 
crypt_single_target_currency = typeof crypt_single_target_currency == "undefined" ? "US Dollar (USD)" : crypt_single_target_currency; 
 
crypt_single_background_color = typeof crypt_single_background_color == "undefined" ? "#FFFFFF" : crypt_single_background_color; 
 
crypt_single_transperency = typeof crypt_single_transperency == "undefined" ? true : crypt_single_transperency; 
 
crypt_single_border_width = typeof crypt_single_border_width == "undefined" ? 1 : crypt_single_border_width; 
 
crypt_single_border_color = typeof crypt_single_border_color == "undefined" ? "#CCCCCC" : crypt_single_border_color; 
 
crypt_single_border_corners = typeof crypt_single_border_corners == "undefined" ? "rounded" : crypt_single_border_corners; 
 
crypt_single_font_family = typeof crypt_single_font_family == "undefined" ? "Arial" : crypt_single_font_family; 
 
crypt_single_font_size = typeof crypt_single_font_size == "undefined" ? "medium" : crypt_single_font_size; 
 
crypt_single_font_color = typeof crypt_single_font_color == "undefined" ? "#000000" : crypt_single_font_color; 
 
crypt_single_display_time = typeof crypt_single_display_time == "undefined" ? true : crypt_single_display_time; 
 

 
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]) + ')'); 
 

 
crypt_single_month_name = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); 
 

 
crypt_single_date = new Date(crypt_single_getPar.timestamp * 1000); 
 
crypt_single_day = FormatNumberLength(crypt_single_date.getDate(), 2); 
 
crypt_single_month = crypt_single_month_name[crypt_single_date.getMonth()]; 
 
crypt_single_year = crypt_single_date.getFullYear(); 
 
crypt_single_hour = FormatNumberLength(crypt_single_date.getHours(), 2); 
 
crypt_single_minutes = FormatNumberLength(crypt_single_date.getMinutes(), 2); 
 
crypt_single_seconds = FormatNumberLength(crypt_single_date.getSeconds(), 2); 
 
crypt_single_time_zone = "UTC+0:00"; 
 

 
if (crypt_single_transperency) 
 
    crypt_single_background_color = 'transparent'; 
 

 
switch (crypt_single_font_size) { 
 
    case 'small': 
 
     crypt_single_font_size = "90%"; 
 
     break; 
 

 
    case 'medium': 
 
     crypt_single_font_size = "110%"; 
 
     break; 
 

 
    case 'large': 
 
     crypt_single_font_size = "150%"; 
 
     break; 
 
} 
 

 
crypt_single_style = 'background: ' + crypt_single_background_color + 
 
    '; border: ' + crypt_single_border_width + 'px solid ' + crypt_single_border_color + ';' + 
 
    'font-family: ' + crypt_single_font_family +'; font-size: ' + crypt_single_font_size + 
 
    '; color: ' + crypt_single_font_color + ';'; 
 

 
if (crypt_single_border_corners == "square") { 
 
    crypt_single_style += "-webkit-border-radius: 0 !important; -moz-border-radius: 0 !important; border-radius: 0 !important;"; 
 
} 
 

 
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>&darr;</b></font>'; 
 

 
    if (crypt_single_getPar.ticker.change >= 0) { 
 
     crypt_single_text_style = '<font style="color:#009900;"><b>&uarr;</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><span style="color:green";> ' + crypt_single_target_currency.match(/.*?\(([0-9a-z]+)\)/i)[1] +' </span>\ 
 
</div>'); 
 
} 
 
else { 
 
    document.write('\ 
 
    <div class="cryptonatorwidget" style="border-radius:4px;padding:10px;' + crypt_single_style + '">\ 
 
    <b>Nenhum preço disponível</b>\ 
 
    </div>'); 
 
} 
 

 
if (crypt_single_display_time && crypt_single_getPar.success != false) 
 
    document.write('<div style="font-size:70%;opacity:0.6;padding-top:10px;">\ 
 
      Updated ' + crypt_single_day + ' ' + crypt_single_month + ' ' + crypt_single_year + ' ' 
 
      + crypt_single_hour + ':' + crypt_single_minutes + ':' + crypt_single_seconds + ' ' 
 
      + crypt_single_time_zone + '\ 
 
     </div>'); 
 

 
document.write('<div id="cryptoticker" style="font-size:10px;opacity:0.6;padding-top:10px;"><span>Powered by <a href="https://www.arkhad.com" style="color:' + crypt_single_font_color + ';" target="_blank">Arkhad</a></span></div>\ 
 
</div>');
div#cryptoticker span { 
 
    display: none; } 
 
    
 

私は何かが欠けていますが、見つけることができませんが見つかりました:/

+0

これを質問に移動できますか?ちょうど編集ボタンを押して、最後に置いてください。 –

+0

実行できないため、コードにはかなりの問題があります。まず、JSコードをhttp://jshint.com/に投げてエラーを見つけることをお勧めします。第2に、複数行のテキストを使用する場合は、バックスラッシュで '\' 'を使用するか、それぞれの独立したテキストを1行に書きますが、変数に繰り返し保存します。 'long_string + ="

Next line
"'あなたの例が実際に動作すると、私はいくつかの進歩があると思います:) –

0

ここでは、最終的な結果^^

です

crypt_single_base_currency = "Decred (DCR)";crypt_single_target_currency = "Bitcoin (BTC)";crypt_single_border_width = 0;crypt_single_font_family = "Sans-Serif";crypt_single_font_color = "#000";crypt_single_display_time = false; 
 

 
function httpGet(theUrl) 
 
{ 
 
    var xmlHttp = null; 
 

 
    xmlHttp = new XMLHttpRequest(); 
 
    xmlHttp.open("GET", theUrl, false); 
 
    xmlHttp.send(null); 
 
    return xmlHttp.responseText; 
 
} 
 

 
function FormatNumberLength(num, length) { 
 
    var r = "" + num; 
 
    while (r.length < length) { 
 
     r = "0" + r; 
 
    } 
 
    return r; 
 
} 
 

 
crypt_single_base_currency = typeof crypt_single_base_currency == "undefined" ? "Bitcoin (BTC)" : crypt_single_base_currency; 
 
crypt_single_target_currency = typeof crypt_single_target_currency == "undefined" ? "US Dollar (USD)" : crypt_single_target_currency; 
 
crypt_single_background_color = typeof crypt_single_background_color == "undefined" ? "#FFFFFF" : crypt_single_background_color; 
 
crypt_single_transperency = typeof crypt_single_transperency == "undefined" ? true : crypt_single_transperency; 
 
crypt_single_border_width = typeof crypt_single_border_width == "undefined" ? 1 : crypt_single_border_width; 
 
crypt_single_border_color = typeof crypt_single_border_color == "undefined" ? "#CCCCCC" : crypt_single_border_color; 
 
crypt_single_border_corners = typeof crypt_single_border_corners == "undefined" ? "rounded" : crypt_single_border_corners; 
 
crypt_single_font_family = typeof crypt_single_font_family == "undefined" ? "Arial" : crypt_single_font_family; 
 
crypt_single_font_size = typeof crypt_single_font_size == "undefined" ? "medium" : crypt_single_font_size; 
 
crypt_single_font_color = typeof crypt_single_font_color == "undefined" ? "#000000" : crypt_single_font_color; 
 
crypt_single_display_time = typeof crypt_single_display_time == "undefined" ? true : crypt_single_display_time; 
 

 
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]) + ')'); 
 

 
crypt_single_month_name = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); 
 

 
crypt_single_date = new Date(crypt_single_getPar.timestamp * 1000); 
 
crypt_single_day = FormatNumberLength(crypt_single_date.getDate(), 2); 
 
crypt_single_month = crypt_single_month_name[crypt_single_date.getMonth()]; 
 
crypt_single_year = crypt_single_date.getFullYear(); 
 
crypt_single_hour = FormatNumberLength(crypt_single_date.getHours(), 2); 
 
crypt_single_minutes = FormatNumberLength(crypt_single_date.getMinutes(), 2); 
 
crypt_single_seconds = FormatNumberLength(crypt_single_date.getSeconds(), 2); 
 
crypt_single_time_zone = "UTC+0:00"; 
 

 
if (crypt_single_transperency) 
 
    crypt_single_background_color = 'transparent'; 
 

 
switch (crypt_single_font_size) { 
 
    case 'small': 
 
     crypt_single_font_size = "90%"; 
 
     break; 
 

 
    case 'medium': 
 
     crypt_single_font_size = "110%"; 
 
     break; 
 

 
    case 'large': 
 
     crypt_single_font_size = "150%"; 
 
     break; 
 
} 
 

 
crypt_single_style = 'background: ' + crypt_single_background_color + 
 
    '; border: ' + crypt_single_border_width + 'px solid ' + crypt_single_border_color + ';' + 
 
    'font-family: ' + crypt_single_font_family +'; font-size: ' + crypt_single_font_size + 
 
    '; color: ' + crypt_single_font_color + ';'; 
 

 
if (crypt_single_border_corners == "square") { 
 
    crypt_single_style += "-webkit-border-radius: 0 !important; -moz-border-radius: 0 !important; border-radius: 0 !important;"; 
 
} 
 

 
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>&darr;</b></font>'; 
 

 
    if (crypt_single_getPar.ticker.change >= 0) { 
 
     crypt_single_text_style = '<font style="color:#009900;"><b>&uarr;</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><span style="color:green";> ' + crypt_single_target_currency.match(/.*?\(([0-9a-z]+)\)/i)[1] +' </span>\ 
 
    </div>'); 
 
} 
 
else { 
 
    document.write('\ 
 
    <div class="cryptonatorwidget" style="border-radius:4px;padding:10px;' + crypt_single_style + '">\ 
 
    <b>Nenhum preço disponível</b>\ 
 
    </div>'); 
 
} 
 

 
if (crypt_single_display_time && crypt_single_getPar.success != false) 
 
    document.write('<div style="font-size:70%;opacity:0.6;padding-top:10px;">\ 
 
      Updated ' + crypt_single_day + ' ' + crypt_single_month + ' ' + crypt_single_year + ' ' 
 
      + crypt_single_hour + ':' + crypt_single_minutes + ':' + crypt_single_seconds + ' ' 
 
      + crypt_single_time_zone + '\ 
 
     </div>'); 
 

 
document.write('<div id="cryptoticker" style="font-size:10px;opacity:0.6;padding-top:10px;"><span>Powered by <a href="https://www.arkhad.com" style="color:' + crypt_single_font_color + ';" target="_blank">Arkhad</a></span></div>\ 
 
</div>');
div#cryptoticker span { 
 
    display: none; }

ありがとうございます!

関連する問題