2015-09-06 165 views
0

我知道這可以通過.change()事件完成,並將其放入$('#console').scrollTop($('#console')[0].scrollHeight);。但問題是textarea是隻讀的,我使用javascript在textarea中輸入文本。Textarea自動向下滾動

對於前: -

$( '#控制檯')文本($( '#控制檯')文本()+ '\ n> _ Optained觸發器'。)。

在這種情況下,textarea不是scrolltobottom,因爲更改事件它沒有響應。

任何替代它或任何其他事件捕獲JavaScript文本在textarea中更改?

回答

1

你可以影響你的元素,而無需一連串事件的jQuery操作:

$('#console').text($('#console').text()+'\n>_ Optained Trigger').scrollTop($('#console')[0].scrollHeight); 

編輯:好吧,我看了你的意見,並解決您可能會引發更改事件手動

//first define the event behaviour 
$('#console').on('change', function(e){ 
    var console = $(this); 
    console.scrollTop($('#console')[0].scrollHeight); 
} 

//then every time you modify the text, trigger the event 
$('#console').text($('#console').text()+'\n>_ Optained Trigger').trigger('change') 
+0

是的我可以做到這一點,但在很多地方(在不同的文件)完成的文本中的這種變化,所以我需要一個事件來檢測他們是否在textarea中的變化。 – squiroid

+0

還有一個輸入事件 – cosmycx