相关疑难解决方法(0)

单击鼠标即可选择所有DIV文本

当用户点击DIV时,如何突出显示/选择DIV标签的内容......我们的想法是突出显示/选择所有文本,这样用户就不需要用鼠标手动突出显示文本了错过了一些文字?

例如,假设我们有一个DIV如下:

<div id="selectable">http://example.com/page.htm</div>
Run Code Online (Sandbox Code Playgroud)

...当用户点击任何该URL时,整个URL文本都会突出显示,以便他们可以轻松地在浏览器中拖动所选文本,或者通过右键单击复制完整的URL.

谢谢!

javascript css

128
推荐指数
9
解决办法
11万
查看次数

CreateTextRange无法在Chrome中使用

在此代码中,createRange无法在Chrome中使用.在IE中,它正在运行.请帮忙解决这个问题.是否有任何其他属性可以像创建范围一样工作.这样对我的项目很有帮助.

<script language=javascript>

    var isSelected;
    function markSelection ( txtObj ) {
      if ( txtObj.createTextRange ) {
        txtObj.caretPos = document.selection.createRange().duplicate();
        isSelected = true;
      }
    }

    function insertTag ( txtName, enclose ) {
        if(document.f_activity_email == null) {
            var tag = document.getElementById('EmailTokenID').value;
        }
        else {
            var formC = document.f_activity_email;
            var tag = formC.EmailTokenID.value;
        }
        var closeTag = tag;
        if ( enclose ) {
            var attribSplit = tag.indexOf ( ' ' );
            if ( tag.indexOf ( ' ' ) > -1 ) …
Run Code Online (Sandbox Code Playgroud)

javascript compatibility google-chrome

14
推荐指数
3
解决办法
3万
查看次数

Chrome Selection.addRange()没有选择(execCommand('copy')用例)

在Chrome中编写一个微小的浏览器扩展程序,将特定网页中的某些特定文本复制到剪贴板.在HTML格式中,人们可以将其粘贴到word,outlook等办公程序中.

document.execCommand('copy')是我使用的命令,它由一个document.onkeydown组合键(Alt + 1)触发,它工作正常 - 但只是第一次.如果您尝试再次按下组合键,它将不执行任何操作.

我找到了它的原因,document.queryCommandEnabled("copy")第一次返回true,任何额外的尝试都返回false.如果我重新加载页面,它第一次再次返回true.此外,如果我在加载页面后点击浏览器窗口外部,然后在浏览器中单击并使用组合键,则会立即返回false,即使是第一次.

function copy(text) {
  var sel = document.createElement("div"); // Creating temporary holder for text to copy

  sel.style.opacity = 0;             sel.style.position = "absolute";  // These are not really required,
  sel.style.pointerEvents = "none";  sel.style.zIndex = -1;            // at least for Chrome

  sel.innerHTML = text; // Put the text to copy into the temporary holder

  document.body.appendChild(sel); // Add the temporary holder to the page

  var range = document.createRange();     // All this is …
Run Code Online (Sandbox Code Playgroud)

javascript clipboard google-chrome execcommand

5
推荐指数
1
解决办法
1687
查看次数