宝玉的blog

专注于web开发技术
随笔 - 81, 评论 - 1563, 引用 - 157

导航

关于


目前致力于ChinaCommunityServer的开发。

msn: junminliu(at)msn.com

标签

每月存档

最新留言

  • re:发布一个爱心小软件——网页抓图
    <p>你好 我看了你的代码 不错啊,请问在asp.net C#中 没有了webbrowser 该怎么实现?</p> <p><a href="http...
    by weblogical(注册) on 2009/9/9 17:22:55
  • re:Openlab V2.0 Beta
    <p>宝玉你好: &nbsp; &nbsp; &nbsp; 我是个.net新手,最近看了openlab(openlab_V2.0_Beta)的源码。 ...
    by isforge(注册) on 2009/6/28 10:10:37
  • re:Openlab V2.0 Beta
    <p>宝玉你好: &nbsp; &nbsp; &nbsp; 我是个.net新手,最近看了openlab(openlab_V2.0_Beta)的源码。 ...
    by isforge(注册) on 2009/6/28 10:10:31
  • re:Openlab V2.0 Beta
    <p>宝玉你好: &nbsp; &nbsp; &nbsp; 我是个.net新手,最近看了openlab(openlab_V2.0_Beta)的源码。 ...
    by isforge(注册) on 2009/6/28 10:10:30
  • re:Openlab V2.0 Beta
    <p>宝玉你好: &nbsp; &nbsp; &nbsp; 我是个.net新手,最近看了openlab(openlab_V2.0_Beta)的源码。 ...
    by isforge(注册) on 2009/6/28 10:10:29
  • re:Openlab V2.0 Beta
    <p>宝玉你好: &nbsp; &nbsp; &nbsp; 我是个.net新手,最近看了openlab(openlab_V2.0_Beta)的源码。 ...
    by isforge(注册) on 2009/6/28 10:10:25
  • re:Openlab V2.0 Beta
    <p>宝玉你好: &nbsp; &nbsp; &nbsp; 我是个.net新手,最近看了openlab(openlab_V2.0_Beta)的源码。 ...
    by isforge(注册) on 2009/6/28 10:10:25
  • re:Openlab V2.0 Beta
    <p>宝玉你好: &nbsp; &nbsp; &nbsp; 我是个.net新手,最近看了openlab(openlab_V2.0_Beta)的源码。 ...
    by isforge(注册) on 2009/6/28 10:10:25
  • re:Openlab V2.0 Beta
    <p>宝玉你好: &nbsp; &nbsp; &nbsp; 我是个.net新手,最近看了openlab(openlab_V2.0_Beta)的源码。 ...
    by isforge(注册) on 2009/6/28 10:10:25
  • re:Silverlight中,防止ComboBox抢焦点
    <p>我是初学者,您已经写了一个 组件上传的功能 。。我在2008下测试通过,,,但是弄2005测试的时候 发现 progress.aspx.cs页面的</p> <p&...
    by jxh12345j(注册) on 2009/4/7 8:55:12
  • ufnnutdh - Google Search
    ufnnutdh - Google Search
    by (匿名) on 2008/10/27 17:44:45
  • veysaync - Google Search
    veysaync - Google Search
    by (匿名) on 2008/10/5 5:20:49
  • mzgmhgio - Google Search
    mzgmhgio - Google Search
    by (匿名) on 2008/9/22 23:34:49
  • rhmhnyma - Google Search
    rhmhnyma - Google Search
    by (匿名) on 2008/9/22 7:48:44
  • re: 发布一个爱心小软件——网页抓图
    Maxthon应该有这个功能
    by passos(匿名) on 2008/7/21 20:05:23

广告

 

今天有人问我一个问题:如何通过js脚本复制网页上的一个表格?看起来似乎比较有难度,不过还是搞定了,顺便把解决这个问题的过程记录下来,希望能对写脚本的兄弟们有所帮助。

以前没有写过这种脚本,不过想起来前不久刚看到一个脚本可以实现全选HTML编辑器的内容,于是想到一个方案:使用脚本将该表格插入HTML编辑器中,然后全选HTML编辑器内容,执行HTML编辑器的复制命令,即可实现复制表格功能,很快搞定:


这样子功能是实现了,不过觉得有点不爽,必须借助HTML编辑器才可,不过从全选HTML编辑器的代码中,注意到了createTextRange()方法,这个方法以前就有用过,只是一直没深入研究过。在Msdn中发现只有Body、TextArea等对象支持createTextRange()方法,继续在msdn中仔细查阅了一下,createTextRange()返回的是一个 TextRange 对象,继续查阅 TextRange 对象,发现其有很多方法,先试了试findText方法,发现只能选中文字,不能选中对象,继续找,终于发现了moveToElementText就是我们要找的方法:


类似于这样的问题,可以想想以前有无写过见过类似的代码,如果没有也可以网上用关键字搜索一把,直接利用现有知识解决。msdn是一个非常好的宝库,就如小学学汉字的字典一样,从里面可以找到绝大部分所需要的资料。正应了那句话,自己动手丰衣足食:)

打印 | 张贴于 2004-12-02 22:50:00 | Tag:Web技术

留言反馈

#如何在网页图片上加复制代码? 编辑
如何在网页图片上加复制代码?
将复制下来的图片可以在QQ发送或在图形软件上粘贴?
我的邮箱:wgl_0815@tom.com
谢谢
2007-08-21 16:44:00 | [匿名:wgl]
#回复: 如何通过js脚本复制网页上的一个表格? 编辑
我是以一个朋友身份和你弄这个网页,我请你记住我不要把我给忘了,我最幸运是认识你 最遗憾的是不能和你在一起 爱的多深 痛的多重 心爱一个人要用心哦 爱你哦。我喜欢和我喜欢的人在一起,我相信我一定会找到她。中一个解不开的情结 /你记住这些话,你不要把我当你的男朋友,你要把我当做朋友.我最幸运是认识你 最遗憾的是不能和你在一起 爱的多深 痛的多重 心中一个解不开的情结
2007-06-09 14:41:00 | [匿名:林露]
#buy tablet tramadol 编辑
Preserving health by too severe a rule is a worrisome malady.
2007-03-29 18:40:00 | [匿名:buy tablet tramadol]
#cheep phentermine 编辑
Get pleasure out of life...as much as you can. Nobody ever died from pleasure.
2007-03-29 14:12:00 | [匿名:cheep phentermine]
#drug 编辑
I like coincidences. They make me wonder about destiny, and whether free will is an illusion or just a matter of perspective. They let me speculate on the idea of some master plan that, from time to time, we're allowed to see out of the corner of our eye.
2007-03-29 10:37:00 | [匿名:drug]
#drug 编辑
I like coincidences. They make me wonder about destiny, and whether free will is an illusion or just a matter of perspective. They let me speculate on the idea of some master plan that, from time to time, we're allowed to see out of the corner of our eye.
2007-03-29 10:35:00 | [匿名:drug]
#cialis online 编辑
Make hunger thy sauce, as a medicine for health.
2007-03-29 06:13:00 | [匿名:cialis online]
#diabetes 编辑
The price one pays for pursuing any profession or calling is an intimate knowledge of its ugly side.
2007-03-29 02:41:00 | [匿名:diabetes]
#valium 编辑
People fail forward to success.
2007-03-26 18:31:00 | [匿名:valium]
#valium 编辑
People fail forward to success.
2007-03-26 18:31:00 | [匿名:valium]
#diabetes 编辑
The release of atomic energy has not created a new problem. It has merely made more urgent the necessity of solving an existing one.
2007-03-26 10:47:00 | [匿名:diabetes]
#ultram 编辑
I sent the club a wire stating, PLEASE ACCEPT MY RESIGNATION. I DON'T WANT TO BELONG TO ANY CLUB THAT WILL ACCEPT ME AS A MEMBER.
2007-03-26 07:40:00 | [匿名:ultram]
#tramadol discount 编辑
Sorrow was like the wind. It came in gusts.
2007-03-24 02:15:00 | [匿名:tramadol discount]
#xenical workability teachware 编辑
I am free of all prejudice. I hate everyone equally.
2007-03-23 22:46:00 | [匿名:xenical workability teachware]
#cheap viagra 编辑
The art of dining well is no slight art, the pleasure not a slight pleasure.
2007-03-23 18:29:00 | [匿名:cheap viagra]
#levitra 编辑
Realize that true happiness lies within you. Waste no time and effort searching for peace and contentment and joy in the world outside. Remember that there is no happiness in having or in getting, but only in giving. Reach out. Share. Smile. Hug. Happiness is a perfume you cannot pour on others without getting a few drops on yourself.
2007-03-23 10:49:00 | [匿名:levitra]
#paxil 编辑
There's so much pollution in the air now that if it weren't for our lungs there'd be no place to put it all.
2007-03-23 06:43:00 | [匿名:paxil]
#vicodin 编辑
The Americans have need of the telephone, but we do not. We have plenty of messenger boys.
2007-03-22 19:14:00 | [匿名:vicodin]
#doctor 编辑
There are plenty of good five-cent cigars in the country. The trouble is they cost a quarter. What this country needs is a good five-cent nickel.
2007-03-22 11:56:00 | [匿名:doctor]
#viagra or cialis 编辑
Truth has beauty, power and necessity.
2007-03-22 00:26:00 | [匿名:viagra or cialis]
#viagra online 编辑
Seize opportunity by the beard, for it is bald behind.
2007-03-21 14:18:00 | [匿名:viagra online]
#propecia circumsphere vox 编辑
Anything looked at closely becomes wonderful.
2007-03-21 10:55:00 | [匿名:propecia circumsphere vox]
#valium 编辑
If men could only know each other, they would neither idolize nor hate.
2007-03-21 06:34:00 | [匿名:valium]
#levitra 编辑
There is still a difference between something and nothing, but it is purely geometrical and there is nothing behind the geometry.
2007-03-20 18:50:00 | [匿名:levitra]
#doctor 编辑
I despise the pleasure of pleasing people that I despise.
2007-03-20 15:18:00 | [匿名:doctor]
#cheap viagra 编辑
It is a good rule in life never to apologize. The right sort of people do not want apologies, and the wrong sort take a mean advantage of them.
2007-03-20 11:58:00 | [匿名:cheap viagra]
#paxil 编辑
Few people think more than two or three times a year; I have made an international reputation for myself by thinking once or twice a week.
2007-03-20 08:38:00 | [匿名:paxil]
#回复: 如何通过js脚本复制网页上的一个表格? 编辑
请问如何复制复选框选中的连接地址,就像www.verycd.com里面的那种复制选中的连接。
2007-03-19 14:01:00 | [匿名:zhang]
#carisoprodol 350 mg 编辑
It is not enough to aim; you must hit.
2007-03-18 00:40:00 | [匿名:carisoprodol 350 mg]
#adipex 编辑
If you want to be respected, you must respect yourself.
2007-03-17 21:21:00 | [匿名:adipex]
#lipitor zocor 编辑
I daresay one profits more by the mistakes one makes off one's own bat than by doing the right thing on somebody's else advice.
2007-03-12 03:49:00 | [匿名:lipitor zocor]
#phentermine adipex 编辑
Men are equal; it is not birth but virtue that makes the difference.
2007-03-09 16:17:00 | [匿名:phentermine adipex]
#re: 如何通过js脚本复制网页上的一个表格? 编辑
学习中,哎,我可真菜啊!
2006-11-06 20:41:00 | [匿名:大学生网]
#re: 如何通过js脚本复制网页上的一个表格? 编辑
一直感为,html编辑器,神奇, 没有到 editor.document.designMode = 'On'; 一句这个就稿定了. 哈哈.
2006-10-30 13:18:00 | [匿名:软件搜索]
#re: 如何最简单地将表格内容发布到一网页上 编辑
也就是做个点击链接该如何做?
2006-04-12 17:36:00 | [匿名:ll]
#re:如何最简单地将表格内容发布到一网页上 编辑
2006-04-12 17:33:00 | [匿名:阿林]
#请问如何选中网页上的一个图片? 编辑
请问如何选中网页上的一个图片?
2005-10-24 15:57:00 | [匿名:jsah]
#re: 如何通过js脚本复制网页上的一个表格? 编辑
firefox就是垃圾!
2005-09-19 15:27:00 | [匿名:shit]
#如何通过js脚本复制网页上的一个表格 编辑
请看博客堂中:《如何通过js脚本复制网页上的一个表格?》
2005-08-09 11:18:00 | [匿名:我们的自由国度]
#re: 如何通过js脚本复制网页上的一个表格? 编辑
在一个图片库里能一点随便一张图片就可以复帛到编辑器里啊。?
2005-06-07 08:41:00 | [匿名:拔草]
#re: ͨjsűҳϵһ 编辑

var memeoryTable = tableAddTr.cloneNode(true);
forBackUpTD.appendChild(memeoryTable);
2005-04-04 13:47:00 | [匿名:CHENLINZHE]
#re: 如何通过js脚本复制网页上的一个表格? 编辑
hehe,not bad! 3Q
2004-12-08 17:45:00 | [匿名:rony]
#re: 如何通过js脚本复制网页上的一个表格? 编辑
代码在FIREFOX里不能用呀~
在FIREFOX里要如何实现HTML编辑器呢?
2004-12-04 17:05:00 | [匿名:norman]
#re: 如何通过js脚本复制网页上的一个表格? 编辑
所谓会者不难,很多问题知道答案后当然觉得很简单,我写这篇blog目的不是FAQ,只是借此分享一下解决问题的一个过程和思路,希望能对初学者有所帮助。
呵呵,见笑了:)
2004-12-03 10:56:00 | [匿名:宝玉]
#re: 如何通过js脚本复制网页上的一个表格? 编辑
这个是很常见的用法啊
2004-12-03 10:43:00 | [匿名:木野狐]
#re: 如何通过js脚本复制网页上的一个表格? 编辑
谢谢mini,效果非常好!
2004-12-03 09:13:00 | [匿名:宝玉]
#re: 如何通过js脚本复制网页上的一个表格? 编辑
function copy(oid)
{
var oControlRange = document.body.createControlRange();
oControlRange.add(oid,0);
oControlRange.select();
document.execCommand("Copy");
}
这样也行,并且可以把子对象复制
2004-12-03 09:06:00 | [匿名:mini]
#re: 如何通过js脚本复制网页上的一个表格? 编辑
好呀,宝玉辛苦了 ,我另外试了一下,还能粘到word 中
2004-12-02 23:09:00 | [匿名:春风]
对不起,目前本随笔不允许发表新评论.

Powered by: Joycode.MVC引擎 0.5.2.0