如何解析浏览器兼容性的可编辑DIV文本 [英] How to parse editable DIV's text with browser compatibility
本文介绍了如何解析浏览器兼容性的可编辑DIV文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将div设为可编辑。当我试图解析div的文本时,我需要做下面的正则表达式。
I make div as editable. while i tried to parse div's text, i was needed to do the below regular expression.
innerDOM = "<div style="cursor: text;">I had downloaded all the material from the Intern,<br>You will find</div><div style="cursor: text;"> </div><div style="cursor: text;">dfvdfvdvdfvdfvdvdvdf</div><div style="cursor: text;"> </div><div style="cursor: text;">dfvdfvdvdfvdfvdfvdfvd</div>"
innerDOM.replace(/<div style="cursor: text">/g, "<br>").replace(/<\/div>/g, "");
正则表达式在firefox和chrome上运行良好。但不是在IE中。我应该做些什么改变?
Above regular expression works good in firefox and chrome. But not in IE. What changes should i do?
请参阅此 FIDDLE 为了更好地理解......
See this FIDDLE for better understanding...
推荐答案
//FINAL ANSWER
var domString = "", temp = "";
$("#div-editable div").each(function()
{
temp = $(this).html();
domString += "<br>" + ((temp == "<br>") ? "" : temp);
});
alert(domString);
请参阅小提琴的答案。
这篇关于如何解析浏览器兼容性的可编辑DIV文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文