【问题标题】:Android: How to select text from WebView, and highlight it onclickAndroid:如何从 WebView 中选择文本,并在单击时突出显示它
【发布时间】:2013-02-05 00:59:39
【问题描述】:

大家好,在我的网络应用程序中,我想打印选定的文本(在段落标签中说这里的内容)。在 Android WebView 中怎么做,如何使用 JavaScript 选择文本??

在此先感谢..

这是我的 JavaScript 代码

<script type="text/JavaScript">

function SelectText()
{
    var txt = '';
     if (window.getSelection)

    {
        txt = window.getSelection();
             }
    else if (document.getSelection)
    {
        txt = document.getSelection();
            }
    else if (document.selection)
    {
        txt = document.selection.createRange().text;
            }
    else return;
document.getElementById("demo").innerHTML=  txt;
}

</script></head>


 <body>
   <p>Hi man how are you?? Hope your doing good..</p>
   <p> id="demo"></p>

  <button> onclick="SelectText()">Selected text</button>

</body>
</html>

【问题讨论】:

标签: javascript android


【解决方案1】:

你写的

<p> id="demo"></p>

应该是

<p id="demo"></p>

这能解决问题还是拼写错误?

【讨论】:

猜你喜欢
  • 2011-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-29
  • 1970-01-01
  • 2011-10-28
  • 1970-01-01
  • 2021-09-18
相关资源
最近更新 更多