- 浏览: 304858 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (243)
- Core Java (13)
- Java (12)
- Android (2)
- Lucene (3)
- J2EE (3)
- Hibernate (2)
- Jsp & Servlet (3)
- Struts2 (3)
- Spring (5)
- JSF (6)
- RichFaces (2)
- HTML & JS & DOM & CSS (87)
- browser (1)
- Ajax & A4J (2)
- Workflow (1)
- Maven (3)
- Linux (2)
- VM & VBOX (1)
- Tomcat (1)
- Cache (3)
- Others (36)
- design (1)
- PHP (1)
- Try.js (1)
- HTML5 && CSS3 && ECMAScript5 (26)
- 疯言疯语 (5)
- mongodb (2)
- Hardware Common Sence (1)
- RESTful (3)
- Nginx (2)
- web安全 (8)
- Page Design (1)
- web performance (1)
- nodejs (4)
- python (1)
最新评论
-
New_Mao_Er:
求最新的版本破解啊!!!
Omondo eclipseUML插件破解 -
konglx:
讲得仔细,谢了
全面分析 Spring 的编程式事务管理及声明式事务管理 -
cilendeng:
对所有post有效只能使用过滤器
说说Tomcat的Server.xml的URIEncoding=‘UTF-8’配置 -
jiulingchen:
mark了,灰常感谢!
JAVA中最方便的Unicode转换方法 -
anlaetion:
这算法可以有
js 字符串搜索算法
忙了几天终于搞出来了这么一个功能,因为是针对特定情况(比如不考虑div)作做的开发,真正使用的话一些地方仍需要改进。做的时候是参考office word的功能来做的,为了用户能够更容易使用。贴上代码(初稿,有点乱,此版本是做了修改之后的版本,兼容ie和firefox):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>create text range</title> <script> var LineHeight = function(){ this.selectedE = document.selection?document.selection:(window.getSelection?window.getSelection():null); this.isIE = this.isIE(); } LineHeight.prototype.isIE = function(){ if (window.navigator.userAgent.indexOf("MSIE")>=1){//如果浏览器为IE return true; }else{ //如果浏览器为Firefox if (window.navigator.userAgent.indexOf("Firefox")>=1){ return false; } } } LineHeight.prototype.dowithParagragh = function(element){ if(element == null || element == 'undefined') return; if(element.nodeName.toLowerCase() == 'p'){ element.style.lineHeight = "200%"; } } LineHeight.prototype.dowithTable = function(element){ if(element == null || element == 'undefined') return; if(element.nodeName.toLowerCase() == 'table'){ var oTds = element.getElementsByTagName('td'); for(var j=0;j<oTds.length;j++){ oTds[j].style.lineHeight = "200%"; } } } LineHeight.prototype.dowithTableInTable = function(element){ if(element == null || element == 'undefined') return; if(element.nodeName.toLowerCase() == 'table'){ var oTds = element.getElementsByTagName('td'); for(var j=0;j<oTds.length;j++){ var oTd = oTds[j]; oTd.style.lineHeight = "200%"; if(oTd.hasChildNodes()){ for(var k=0;k<oTd.childNodes.length;k++){ var oChild = oTd.childNodes[k]; if(oChild.nodeType == 1 && oChild.nodeName.toLowerCase() == 'table'){ this.dowithTableInTable(oChild); } } } } } } LineHeight.prototype.dowithParagraghOrTable = function(element){ if(element == null || element == 'undefined') return; if(element.nodeName.toLowerCase() == 'p'){ element.style.lineHeight = "200%"; var oTables = element.getElementsByTagName('table'); if(oTables == null || oTables.length == 0) return; for(var i=0;i<oTables.length;i++){ this.dowithTableInTable(oTables[i]); } }else if(element.nodeName.toLowerCase() == 'table'){ this.dowithTableInTable(element); } } /*HTMLElement.prototype.contains=function(o){ while(o!=null){ if(o==this)return true; o=o.parentNode; } return false; }*/ LineHeight.prototype.contains = function(a, b){//扩展的contains return a.contains ? a != b && a.contains(b) : !!(a.compareDocumentPosition(b) & 16); } LineHeight.prototype.test = function(){ var range; var startPE; var endPE; var oDiv; var rng; if(this.isIE){ range = this.selectedE.createRange(); rng = range.duplicate(); oDiv = document.createElement('div'); oDiv.innerHTML = range.htmlText; range.collapse(); startPE = range.parentElement(); rng.collapse(false); endPE = rng.parentElement(); }else{ range = this.selectedE.getRangeAt(0); startPE = range.startContainer.parentNode; endPE = range.endContainer.parentNode; } if(startPE.nodeName.toLowerCase() == 'td' && endPE.nodeName.toLowerCase() == 'td'){ while(startPE.nodeName.toLowerCase() != 'table'){ startPE = startPE.parentNode; } while(endPE.nodeName.toLowerCase() != 'table'){ endPE = endPE.parentNode; } if(startPE == endPE || this.contains(startPE,endPE)){ this.dowithTableInTable(startPE); return; }else if(this.contains(endPE,startPE)){ this.dowithTableInTable(endPE); return; }else{ startPE = this.isIE?range.parentElement():range.startContainer.parentNode; endPE = this.isIE?rng.parentElement():range.endContainer.parentNode; } }else if(startPE.nodeName.toLowerCase() == 'td' ^ endPE.nodeName.toLowerCase() == 'td'){ while(startPE.nodeName.toLowerCase() != 'p'){ if(startPE.nodeName.toLowerCase() == 'body') break; startPE = startPE.parentNode; } while(endPE.nodeName.toLowerCase() != 'p'){ if(endPE.nodeName.toLowerCase() == 'body') break; endPE = endPE.parentNode; } //document.getElementsById('d');//debug if(startPE == endPE){ this.dowithParagraghOrTable(startPE); return; }else{ startPE = this.isIE?range.parentElement():range.startContainer.parentNode; endPE = this.isIE?rng.parentElement():range.endContainer.parentNode; } } //document.getElementsById('d');//debug while(startPE.nodeName.toLowerCase() != 'p'){ if(startPE.nodeName.toLowerCase() == 'body') break; this.dowithTable(startPE); startPE = startPE.parentNode; } //document.getElementsById('d');//debug while(endPE.nodeName.toLowerCase() != 'p'){ if(endPE.nodeName.toLowerCase() == 'body') break; this.dowithTable(endPE); endPE = endPE.parentNode; } if(startPE == endPE){ this.dowithParagraghOrTable(startPE); return; } this.dowithParagraghOrTable(startPE); this.dowithParagraghOrTable(endPE); if(this.isIE){ if(oDiv.hasChildNodes() && oDiv.childNodes.length >= 3){ var nextE = startPE.nextSibling; this.dowithParagraghOrTable(nextE); for(var i=2;i<oDiv.childNodes.length-1;i++){ nextE = nextE.nextSibling; this.dowithParagraghOrTable(nextE); } } }else{ var docFragment = range.cloneContents(); var count = 0; if(docFragment.hasChildNodes()){ for(var i=0;i<docFragment.childNodes.length;i++){ var oChild = docFragment.childNodes[i]; if(oChild.nodeType == 3 && oChild.nodeValue == '\n') continue; else count++; } } var nextE = startPE.nextSibling; this.dowithParagraghOrTable(nextE); for(var i=0;i<count-2;i++){ nextE = nextE.nextSibling; this.dowithParagraghOrTable(nextE); } } } function test1(){ var o = new LineHeight(); o.test(); } </script> </head> <body onmouseup='test1();'> <p> this is a function <span style="background-color:red">text of object of textrange</span>.you will find out how to use it.<br/> this is the <strong>second line for test the</strong> object of textrange.<br/> this is the third line for <strike>test the object</strike> of textrange. </p> <p> this is the <strong>second paragragh for</strong> test,<br/> this is the second line in paragragh two for test. </p> <p> this <strong>is the third paragragh for test,</strong><br/> this is the second line in paragragh three for test. </p> <p> this is a function <span style="background-color:red">text of object of textrange</span>.you will find out how to use it.<br/> this is the <strong>second line for test the</strong> object of textrange.<br/> <table border=1> <tr> <td>sdfasdfasdf</td> <td>sadfdsafsaf</td> <td>sdfasdf</td> <td>asdfasdfasf</td> </tr> <tr> <td>sadfsaf</td> <td>asdfasf</td> <td>asdfsadfsda</td> <td>asdfsadfsaf</td> </tr> </table> this is the third line for <strike>test the object</strike> of textrange. </p> <p> this is the <strong>second paragragh for</strong> test,<br/> this is the second line in paragragh two for test. </p> <table border=1> <tr> <td>sdfasdfasdf</td> <td>sadfdsafsaf</td> <td>sdfasdf</td> <td>asdfasdfasf</td> </tr> <tr> <td>sadfsaf</td> <td>asdfasf</td> <td>asdfsadfsda</td> <td>asdfsadfsaf</td> </tr> </table> <p> this <strong>is the third paragragh for test,</strong><br/> this is the second line in paragragh three for test. </p> <p> this is a function <span style="background-color:red">text of object of textrange</span>.you will find out how to use it.<br/> this is the <strong>second line for test the</strong> object of textrange.<br/> <table border=1> <tr> <td>sdfasdfasdf</td> <td>sadfdsafsaf</td> <td>sdfasdf</td> <td>asdfasdfasf</td> </tr> <tr> <td> <table border=1> <tr> <td>gggggggggggggggggggggggggggg<br/>gggggggggggggggggggggggggggg</td> <td>hhhhhhhhhhhhhhhhhhhhhhhhhhh<br/>hhhhhhhhhhhhhhhhhhhhhhhhhhh</td> </tr> <tr> <td>bbbbbbbbbbbbbbbbbbbbbbbbbbbb<br/>bbbbbbbbbbbbbbbbbbbbbbbbbbb</td> <td>mmmmmmmmmmmmmmmmmmmmmmmmmmmmm<br/>mmmmmmmmmmmmmmmmmmmmmmmmmm</td> </tr> </table> </td> <td>asdfasf</td> <td>asdfsadfsda</td> <td>asdfsadfsaf</td> </tr> </table> this is the third line for <strike>test the object</strike> of textrange. </p> <p> this <strong>is the third paragragh for test,</strong><br/> this is the second line in paragragh three for test. </p> </body> </html>
- textrange.rar (1.9 KB)
- 下载次数: 20
发表评论
-
循环数组的逻辑怎么写
2015-03-23 10:24 616应用场景这样的: var imgUrls = [ ... -
发布`代码生成器`
2014-11-17 00:45 559闲话不说,直接上地址 npm: https://www. ... -
MutationObserver
2014-10-27 15:29 1063MutationObserver MutationObse ... -
a simple mvvm library - bird
2014-10-09 18:26 699see here:https://github.com/i ... -
遍历dom tree是一件相当耗时的事情
2014-09-23 01:15 704遍历dom tree是一件相当耗时的事情,尤其是在遍历的同时 ... -
今天再讲下js里的继承
2014-09-18 00:27 663js的继承说简单也很简单,请看: function ... -
Text 类型
2014-09-05 18:52 804文本节点由Text类型表 ... -
JavaScript插入动态脚本
2014-09-05 18:47 606动态脚本指的是在页面加载时不存在,但将来的某一时刻通过修改该 ... -
innerHTML插入<style>元素
2014-09-05 18:37 1109通过innerHTML写入<style>元素没 ... -
CSS实现相对浏览器窗口定位彻底研究
2014-09-05 18:33 3666Web Developer / Designer 经常需要将 ... -
JavaScript插入动态样式
2014-09-05 18:07 571能够把CSS样式包含到HTML页面中的元素有两个。其中,& ... -
再理解jQuery;delete原型属性
2014-05-13 22:05 1822以前用jQuery的时候曾粗略看了它的源码,但却不求甚解。 ... -
javascript &&和||
2012-07-23 00:38 679一直以为 && 和 || ... -
undefined 和 void 0 的区别
2012-07-20 11:15 682在读backbone源码时看见这么一段代码: if ( ... -
Fiddler - 前端开发值得拥有
2012-07-16 14:41 791最近换了新工作,搬了新家,换了新室友,一切都在重新开始。 ... -
说说我的web前端之路,分享些前端的好书
2012-07-16 14:38 762WEB前端研发工程师,在国内算是一个朝阳职业,这个领域没 ... -
JavaScript实现 页面滚动图片加载
2012-07-16 14:29 648又到了这个月的博客时间了,原计划是打算在这个月做一个的功 ... -
JavaScript 操作 Cookie
2012-07-16 11:18 651从事web开发也有些日 ... -
Javascript定义类(class)的三种方法
2012-07-12 12:35 562程序员们做了很多探索,研究如何用Javascript模拟”类” ... -
服务端解决跨源共享
2012-06-21 10:18 4491跨源资源共享是web开发领域中一个非常有趣的话题,互联网 ...
相关推荐
一直苦恼FCKeditor编辑器不能设置行距,文字设置大了就重叠在一起,终于找到解决办法了,发上来和大家分享!
C# ListView添加行距 源代码 ListView添加行距 一、问题 listview控件,可以实现增大行距吗?行与行太紧了,不好看呀。 有办法可以实现吗? 我不想通过加大字体的方法,因为字体大了,行距还是近呀。 我要的是增大行...
excel如何设置行距.doc
tinyMCE 富文本编辑器 line-height 行高插件。 tinyMCE富文本编辑器line-height行高插件,下载后放在tinyMCE插件的plugins文件夹中,之后初始化中引入plugins,即可在toolbar中展示 tinyMCE line-height 行高插件
将行距增加到和整个DIV一样高 line-height:200px;然后插入文字,就垂直居中了。缺点是要控制内容不要换行 2. margin加倍的问题 设置为float的div在ie下设置的margin会加倍。这是一个ie6都存在的bug。解决方案是在这...
Word2021怎么设置行距?行距设置详细解说.docx
在 fck中添加行距 功能插件,需要的朋友可以参考下。
在NotePad中,当设置字体大于11点时,行距太小,难于阅读,本编辑器的行距大于记事本,可阅读性好,并可打印,预览. 2). 一个简单的Web浏览器. 可以在Windows资源管理器中,点击右键,选择用本程序打开html/htm/txt文件。...
FCKeditor添加行距操作详细步骤
该pdf编辑器支持从其他应用添加图像,表格和绘图,并允许用户编辑任何类型的文本文档,对其中的文本、字体、大小、颜色、边距、行距以及下划线等文本信息进行直接编辑,并将其转换为PDF文件,同时Infix PDF Editor还...
最新版fckeditor V2.6.4的配置,其中增加了几种常用的字体、文字大小和比较流行的QQ表情,并且配置了上传文件的类型,同时增加了类似word的行距功能,另外所有的设置都是通过自己定义的myfckconfig.js文件来进行配置...
Word2021如何设置行距?.docx
PPT文本行距设置。大猫菲菲21号教程:文本行距。选中文本框-开始选项卡-选择常用行距或者设置行距。可以设置1.5倍行距、1.0倍行距、多倍行距或固定值。
设置行距与段间距PPT学习教案.pptx
因为代码中很少注释,我在这里说一下关键:重点是GDI+的DrawDriverString的功能,每个字符需要一个POINTF来定位,该POINTF的原点0,0不是左上角,而是左下角,X=字符左边界,Y(当为0时,实际值为字符行距,需要除以...
拥有无与伦比的易用性和出类拔萃的高级文本处理能力,诞生的初衷就是为了帮助广大用户快速高效编辑PDF文件,像Word等文字处理程序一样轻松编辑PDF文档,该pdf编辑器支持从其他应用添加图像,表格和绘图,并允许用户...
fckeditor 2.6.6 for asp版 带行距功能 本人已测试,可以调整行距 样式地址:http://www.gdwd.net/bianji_test.asp
Word2021中设置行距的两种方法.docx
自定义颜色、字体、工具栏、快捷键设置,可以调整行距,避免中文排列过于紧密,具有选择文本列块的功能(按ALT 键拖动鼠标),并允许无限撤消、重做,总之功能多多,使用方便,是替代记事本的最佳编辑器。支持各类语言