2014-04-09 42 views
1

我有一個書籤,追加當前重點輸入?

enter image description here

我所試圖做的是,附加的元素,以當前的文本區域集中input.For例如,如果用戶關注(點擊),然後點擊我的書籤,我想要在該textarea中添加「Hello」。我試過這個;

<a href=" javascript:(function(){ 
var theDiv = document.getElementById("contentarea"); 
var content = document.createTextNode("Hello"); 
theDiv.appendChild(content); 
})(); 
">this</a> 

但它只適用於我已包括的div id(contentarea)。如何附加當前重點輸入?

回答

3

嘗試用document.activeElement,如:

<a href='javascript:(function(){ 
var theDiv = document.activeElement; 
var content = document.createTextNode("Hello"); 
theDiv.appendChild(content); 
})(); 
'>this</a> 
1

逃離報價和使用document.activeElement

<a href='javascript:(function(){ 
var theDiv = document.activeElement; 
var content = document.createTextNode("Hello"); 
theDiv.appendChild(content); 
})(); 
'>this</a> 
+0

雖然OP需要做到這一點,這不是一個答案,眼下的問題。 –

+0

@jsve,我錯過了。我已更新。 –