使用 Javascript 在 SharePoint 中将文本转换为 HTML
我在 SharePoint 2007 中有一个摘要单行文本列,它是多行文本列的截断。经历复杂的过程< /a> 到达那里,它会变成文本,然后需要转换回 HTML,这样 这样的标签就不会显示。如果多行列是富文本,则以下代码有效,但如果是增强型富文本,则无效。有谁有方便的代码来完成这项工作吗? (注意:我正在研究它,但到目前为止还没有真正完成任何 JavaScript,所以进展缓慢)。
<script type="text/javascript">
var theTDs = document.getElementsByTagName("TD");
var i=0;
var TDContent = " ";
while (i < theTDs.length)
{
try
{
TDContent = theTDs[i].innerText || theTDs[i].textContent;
if (TDContent.indexOf("<div") == 0)
{
theTDs[i].innerHTML = TDContent;
}
}
catch(err){}
i=i+1;
}
</script>
我现在得到的结果是不可见的,因为使用增强型富文本时,div 标签的长度超过了 45 个字符的截断限制。
I have a summary single-line text column in SharePoint 2007 that is a truncation of a multi-line text column. Going through the complicated process to get there, it turns into text which then needs to be converted back to HTML, so that the tags like <div>
don't show. The following code works if the multi-line column is rich text, but not if it's enhanced rich text. Does anyone have the code handy to make this work? (Note: I am working on it but haven't really done any javascript up until now, so it's slow going).
<script type="text/javascript">
var theTDs = document.getElementsByTagName("TD");
var i=0;
var TDContent = " ";
while (i < theTDs.length)
{
try
{
TDContent = theTDs[i].innerText || theTDs[i].textContent;
if (TDContent.indexOf("<div") == 0)
{
theTDs[i].innerHTML = TDContent;
}
}
catch(err){}
i=i+1;
}
</script>
The result I'm getting now is nothing visible, because with enhanced rich text the div tag is longer than my 45 character truncation limit.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如何使用 Christophe 的 技术来输出 HTML计算列。
具体来说,他编写了 javascript,将编码后的 HTML(您现在已经得到的)转换为 HTML。
将以下内容添加到同一页面上的内容编辑器 Web 部件 (CEWP) 中。
How about using Christophe's techniques to output HTML using a calculated column.
Specifically he has written javascript that will turn the encoded HTML (which you've now got) into HTML.
Add the following into a Content Editor Web Part (CEWP) on the same page.
我已经从下面的链接修改了 TextToHTML 代码,源是 PathToSharePoint.com,并且我添加了一个事件侦听器,该事件侦听器可以在 IE 兼容模式下成功地在 SharePoint 2016 上工作,该模式以 IE10 和 Chrome 最新版本运行: Sharepoint 2010 中的文本到 Html 转换
I have modified the TextToHTML code from below link, source is PathToSharePoint.com and I have added an event listener which works on SharePoint 2016 successfully in IE compatiblity mode which runs as IE10 and Chrome latest version: Text to Html conversion in Sharepoint 2010