在JSON对象上显示2个条件

Show 2 condition on JSON object

本文关键字:2个 条件 显示 JSON 对象      更新时间:2023-09-26

如何在diffrentdiv上显示引号和新引号条件。请帮助我想显示2个条件,我的代码是这样的:

function setup() {
    output = document.getElementById("output2");
    var ws = new WebSocket('wss://www.binary.com/websockets/v3?l=RU');
    ws.onopen = function(evt) {
        ws.send(JSON.stringify({ticks:'R_50'}));
    }
    ws.onmessage = function(msg) {
        var quote = JSON.parse(msg.data).tick.quote;
        var newquote = quote.substr(-1);
        log(newquote);//here should be semi-colon
    } 
}
function log(info) {
    //Display information on screen
    var p = document.createElement("p");
    p.innerHTML = info;
    output.appendChild(p);
    console.log(info);
}
 function sendMessage(msg) {
    ws.send(msg);
    log("TICKS");
    ws.close();
}
window.addEventListener("load", setup, false);

为什么不在HTML中创建两个不同的div,然后进行

HTML

<div id="quote-div"></div>
<div id="newquote-div"></div>

JavaScript

// Let id of div be an argument of function
function log(info, id) {
            var p = document.getElementById(id);
            p.innerHTML = info;
        }
// and use it like
var quote = JSON.parse(msg.data).tick.quote;
var newquote = quote.substr(-1);
log(quote, "quote-div");
log(newquote, "newquote-div");