在contenteditable div中单击按钮时选择文本(可见)

问题描述:

我想单击按钮时选择contenteditable div中的所有文本。有点像在contenteditable div中单击按钮时选择文本(可见)

document.getElementById("myTextArea").select() 

我看着创造一个范围,但不是对用户可见。

有没有办法在JavaScript(使用闭包库)做到这一点?

对不起,我不明白你想要什么

function highlight(element){ 
     var inner = document.getElementById(element).innerText; 
     inner = "<span class=\"highlighted\">" + inner + "</span>" 
    } 
    <style> 
     span .highlighted{ 
     background-color: yellow; 
     } 
    <style> 
+0

谢谢你,我用css突出显示了文字,因为我找不到可以的东西。也许封闭库编辑器会工作,但现在已经解决了。 – HMR 2013-06-04 01:25:46

var x = document.getElementById("myTextArea").innerText; 

此行得到的任何东西的内容有一个id

document.getElementById("myTextArea").innerText = x; 

这条线设置内容

现在把这些代码在一个函数并调用它的onclick这样

<input type="submit" onClick="functionname();" id="submit"> 
+0

正在通过我的问题,看看我是否有任何需要选择正确的答案。 innerText不被许多浏览器支持,并且一些会给你.textContent(这不会正确地给你空白)。我只是在单击按钮时突出显示文字。谢谢你的回答,并对迟到的回复感到抱歉。 – HMR 2013-06-04 01:23:36