先用var关键字创建变量,然后直接写在赋值符号后面。
var price; var quantity; var total; price = 5; quantity = 14; total = price * quantity; var el = document.getElementById('cost'); el.textContent = '$' + total;