原生态js方法实现全选复制功能
我的demo网站想做一个复制代码的功能,可是原生态的js只有ie下才能实现,其他浏览器都需要flash来实现复制功能,我又不想用flash,鼓捣了很久,不能复制,我起码能做一个全选的功能吧。

下面是复制的代码:
function selectCode(objid){
var obj = document.getElementById(objid);
obj.select();
}
function selectText(obj) {
var text = obj;
if (document.body.createTextRange) {
var range = document.body.createTextRange();
range.moveToElementText(text);
range.select();
} else if (window.getSelection) {
var selection = window.getSelection();
var range = document.createRange();
range.selectNodeContents(text);
selection.removeAllRanges();
selection.addRange(range);
} else {
alert("none");
}
}
这里可以预览效果:
代码预览
原生态JS的方法调用CLASS元素标签 原生态js实现ajax的get和post的方法介绍
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.