【问题标题】:Give an effect to all over the page except an element对除元素之外的整个页面产生影响
【发布时间】:2013-03-14 09:58:19
【问题描述】:

我想将此代码放在我的页面上:

function addLink() {  
    var body_element = document.getElementsByTagName('body')[0];  
    var selection; selection = window.getSelection();  
    var pagelink = "<br /><br /> original: <a href='"+document.location.href+"'>"+document.location.href+"</a>";  
    var copytext = selection + pagelink;  
    var newdiv = document.createElement('div'); newdiv.style.position='absolute';  
    newdiv.style.left='-99999px';  
    body_element.appendChild(newdiv);  
    newdiv.innerHTML = copytext;  
    selection.selectAllChildren(newdiv);  
    window.setTimeout(function() {  
        body_element.removeChild(newdiv);  
    }, 0);
} 
document.oncopy = addLink;

但此代码操作适用于所有标签,我不想在“textareas”中操作。

【问题讨论】:

  • 我不明白 - 你想用这个脚本达到什么目的?

标签: javascript jquery arrays dom-events


【解决方案1】:

addlink() 之前测试tagName

document.body.addEventListener('copy', function (e) {
    if (e.target.tagName === 'textarea') {
        return;
    }
    addlink()
}

【讨论】:

  • 用我的代码替换 document.oncopy = addLink; 行。
  • 非常感谢。但是当我测试新代码时,它不起作用!!
猜你喜欢
  • 2023-03-30
  • 2014-09-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-15
  • 2020-05-18
  • 2014-11-09
  • 2014-07-29
相关资源
最近更新 更多