2009-04-13 75 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();