![](/img/trans.png)
[英]How do I refernce a DOM element by ID using a variable in Javascript?
[英]How do I print the variable in HTML using Javscipt DOM?
我將以下App返回值返回給我的函數:
app.get('/account/balance/:email', function (req, res) {
console.log('Your remaining balance is: ' + db.get('account').find({email: 'bill@gmail.com'}).value().balance);
res.send(db.get('account').find({email: 'bill@gmail.com}).value().balance);
});
// The function below send and recive request via URL in the function
function balance() {
var email = 'bill@gmail.com'
var bal = document.getElementById("RemainingBalance");
var url = '/account/balance/' + email;
superagent
.get(url)
.end(function(err, res){
if(err){
console.log(err);
}
else{
console.log(res);
bal.innerHTML = JSON.stringify(res.body);
}
});
}
我想要在我的html網頁上打印'balance'值的函數,我可以使用上面的代碼在控制台上打印abalance,但是我無法在html上打印它。
HTML代碼:
<input type="email" id="balanceEmail" placeholder="email">
<input type="button" class="btn btn-light" name="balance" onclick="balance()" value="Show Balance">
<div class="" >
<p id="RemainingBalance"></p>
</div>
解決了! 我必須在res.send()中輸入正確的字符串;
解決了! 多謝你們!
請嘗試替換此行:
bal.innerHTML = JSON.stringify(res.body);
至
document.getElementById("enter_id_name_where_you_wont_to_show_balence").innerHTML = bal;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.