我是javascript新手。我想使用标记在同一行中打印输出而没有任何换行符。通常,我的输出是单行显示,但是当我将其与tag一起加入时,输出将显示在不同的行中。这是我的代码。引导我通过。
https.get(url, function(response) {
console.log(response.statusCode + 'OK');
response.on('data', function(data) {
const weatherData = JSON.parse(data);
const temp = weatherData.main.temp;
const desc = weatherData.weather[0].description;
console.log(temp);
res.send(
'<h1>The temperature in London is ' + '<h1>' + temp + '<h1> ° Celsius.'
);
});
});
因为H1
默认为块元素,表示它适合其父元素,请将其更改为:
res.send(
'<h1>The temperature in London is ' + '<h1 style="display:inline-block;">' + temp + '<h1> ° Celsius.'
);
或使用内联元素,例如span