$('td').click(function () {
var total = $('<div id="total"></div>')
var price = +($(this).text())
var old = +($('#total').text())
var newPrice = (old + price)
$('<div class="notice"></div>')
.append('<div class="skin"></div>')
.append($('<div class="content"></div>').text('Total price:' + " " + $('#total').text(newPrice)))
.hide()
.appendTo('#panel_two')
.fadeIn(1000);
$('#panel_two').fadeIn().appendTo('#windowContainer');
}
我得到对象对象错误,我试图显示我的newPrice(总价格:)任何想法?
然而,这很好用:
$(document).ready(function(){
$('td').click(function(){
var Price = +($(this).text());
var Old = +($('#Total').text());
var New = (Old + Price);
$('#Total').text(New);
})
})
答案 0 :(得分:0)
$('<div class="content"></div>')
.text('Total price:' + " " + $('#total').text(newPrice) )
基本上是指“查找#total
”,将其文本设置为newPrice
的值,将.text(...)
的返回值与"Total price: "
连接起来,并将其设置为文本新元素“。
现在,$('#total').text(newPrice)
的返回值为$('#total')
,而不是newPrice
。也就是说,没有什么值得被转换为字符串进行连接。
也许这就是你想要的?:
$('#total').text(newPrice);
$('<div class="content"></div>').text('Total price:' + " " + newPrice)
//...