2009-04-13 64 views
1

我正在使用jquery滑块并使用append()更新值,但它将继续添加它,除非我在开​​始事件中将其清空。有没有一种方法可以在每次执行操作时更新值而不是将其打印出来。我试过replaceWith,但没有运气。事件更新div

start: function(event, ui){ 
    $('#current_value').empty();  
}, 
slide: function(event, ui){ 
    $('#current_value').fadeIn().append('Value is '+ui.value); 
}, 

回答

3

你可能要像

slide: function(event, ui){ 
    $('#current_value').text('Value is '+ui.value); 
    $('#current_value').fadeIn(); 
} 

text()文档

+0

谢谢你的。迄今为止效果很好。 HTML也适用于我在其他答案中看到的内容。只是一种不同的方法? – Coughlin 2009-04-13 19:14:02

1

如果我理解你的权利,你应该:

var existing = $('#current_value').html(); 
$('#current_value').html(existing + ui.value).fadeIn(); 
2

你需要使用HTML()不追加(),附加在给定元素的末尾添加值,HTML设置的innerHTML对于给定的元素。

$('#current_value')。html('Value is'+ ui.value).fadeIn();