CSS數(shù)字幣是一種數(shù)字貨幣,可以在互聯(lián)網(wǎng)上使用。但是,如果要將CSS數(shù)字幣轉(zhuǎn)換為其他貨幣,就需要使用外部服務(wù)。以下是一些常用的轉(zhuǎn)換方式:
//使用API轉(zhuǎn)換 var url = "https://api.coinmarketcap.com/v1/ticker/"; var currency = "USD"; var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { var data = JSON.parse(xmlhttp.responseText); for (var i = 0; i < data.length; i++) { if (data[i].symbol == "CSS") { var price = data[i].price_usd; var total = price * CSS; document.getElementById("result").innerHTML = total + " " + currency; } } } }; xmlhttp.open("GET", url, true); xmlhttp.send(); //使用第三方網(wǎng)站轉(zhuǎn)換 var url = "https://www.worldcoinindex.com/apiservice/json?key=YourAPIKey&label=css&fiat="; var currency = "USD"; var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { var data = JSON.parse(xmlhttp.responseText); var price = data.Markets[0].Price; var total = price * CSS; document.getElementById("result").innerHTML = total + " " + currency; } }; xmlhttp.open("GET", url + currency, true); xmlhttp.send();
注:前面的CSS指的是數(shù)字幣,后面的CSS指的是需要轉(zhuǎn)換的數(shù)量。