在javascript中检索富文本框共享点

发布于 2024-10-15 16:08:06 字数 1048 浏览 3 评论 0原文

我有 CustomNewForm 用于在共享点列表中插入项目。

这些字段是“原因”和“原因概览”;两个多行富文本字段。我需要将一些文本从“原因”复制到“原因概述”。(子字符串) 我尝试通过工作流程完成此操作,但找不到获取表单字段的子字符串的解决方案。

我正在尝试从 javascript 中的“Reason”字段获取值;但无法这样做。

我的代码::(不起作用)

<script type="text/javascript">
function PreSaveAction() 
{ 
    var Reason = getTagFromIdentifierAndTitle("textarea","TextField","Reason");  
    var Original = getTagFromIdentifierAndTitle("textarea","TextField","Reason Overview"); 
    alert('Hi');
    Original.innerHTML=Reason.innerHTML;
    return true;
}

function getTagFromIdentifierAndTitle(tagName, identifier, title) 
{
    var len = identifier.length;

    var tags = document.getElementsByTagName(tagName);

    for (var i=0; i < tags.length; i++) 
    {
        var tempString = tags[i].id;

        if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) 
        {
            return tags[i];
        }
    }
        return null;
}
</script>

有什么方法可以完成这个任务吗?

I have CustomNewForm for inserting items in the sharepoint list.

The fields are "Reason" and "Reason OverView"; both Multiple Line Rich Text fields. I need to copy some text from "Reason" to "Reason Overview".(A substring)
I tried to get this done with workflow but couldn't find a solution to get a substring of a form field.

I am trying to get the value from "Reason" field in javascript; but unable to do so.

MY CODE :: (not working)

<script type="text/javascript">
function PreSaveAction() 
{ 
    var Reason = getTagFromIdentifierAndTitle("textarea","TextField","Reason");  
    var Original = getTagFromIdentifierAndTitle("textarea","TextField","Reason Overview"); 
    alert('Hi');
    Original.innerHTML=Reason.innerHTML;
    return true;
}

function getTagFromIdentifierAndTitle(tagName, identifier, title) 
{
    var len = identifier.length;

    var tags = document.getElementsByTagName(tagName);

    for (var i=0; i < tags.length; i++) 
    {
        var tempString = tags[i].id;

        if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) 
        {
            return tags[i];
        }
    }
        return null;
}
</script>

Any way to get this done??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遗心遗梦遗幸福 2024-10-22 16:08:06

我用这个解决了它

<script type="text/javascript">
function PreSaveAction() 
{ 
    var Reason = getTagFromIdentifierAndTitle("textarea","TextField","Reason");  
    var Original = getTagFromIdentifierAndTitle("textarea","TextField","Reason Overview"); 
    var reasonText = RTE_GetEditorDocument(Reason.id);

    var reasonOverviewText = reasonText.body.innerText;
    if(reasonOverviewText.length>=20)
    {
        reasonOverviewText = reasonOverviewText.substring(0,20)+'......';
        Original.innerText = reasonOverviewText;
    }
    else
    {
        Original.innerText = reasonOverviewText;
    }
    return true;
}

function getTagFromIdentifierAndTitle(tagName, identifier, title) 
{
    var len = identifier.length;

    var tags = document.getElementsByTagName(tagName);

    for (var i=0; i < tags.length; i++) 
    {
        var tempString = tags[i].id;

        if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) 
        {
            return tags[i];
        }
    }
        return null;
}
</script>

I solved it using this

<script type="text/javascript">
function PreSaveAction() 
{ 
    var Reason = getTagFromIdentifierAndTitle("textarea","TextField","Reason");  
    var Original = getTagFromIdentifierAndTitle("textarea","TextField","Reason Overview"); 
    var reasonText = RTE_GetEditorDocument(Reason.id);

    var reasonOverviewText = reasonText.body.innerText;
    if(reasonOverviewText.length>=20)
    {
        reasonOverviewText = reasonOverviewText.substring(0,20)+'......';
        Original.innerText = reasonOverviewText;
    }
    else
    {
        Original.innerText = reasonOverviewText;
    }
    return true;
}

function getTagFromIdentifierAndTitle(tagName, identifier, title) 
{
    var len = identifier.length;

    var tags = document.getElementsByTagName(tagName);

    for (var i=0; i < tags.length; i++) 
    {
        var tempString = tags[i].id;

        if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) 
        {
            return tags[i];
        }
    }
        return null;
}
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文