【问题标题】:"Rich text editor" read only does not work“富文本编辑器”只读不起作用
【发布时间】:2018-03-06 10:59:25
【问题描述】:

我不确定我做错了什么。 我有这个输入文本区域,我希望它只能在 A sharePoint 站点中读取,所以我编写了一个通过 id 选择元素并使其只读的方法,它应该很简单,但它对我不起作用。 这是我的方法:

function ReadOnlyRich()
{
  document.getElementById("ctl00_m_g_74c26ddd_a3bd_4c7b_877d_6a60c1035973_ctl00_ctl05_ctl15_ctl00_ctl00_ctl04_ctl00_ctl00_TextField_inplacerte").readOnly = true;
}

该元素的视图源代码如下所示:

<span dir="none">
  <div class='ms-rtestate-field ms-rtefield' style=''>
    <div id='ctl00_m_g_74c26ddd_a3bd_4c7b_877d_6a60c1035973_ctl00_ctl05_ctl15_ctl00_ctl00_ctl04_ctl00_ctl00_TextField_inplacerte_label' style='display:none'>
     Rich text editor QBIQ no & (Title)
    </div>
    <div class=' ms-rtestate-write ms-rteflags-0' id='ctl00_m_g_74c26ddd_a3bd_4c7b_877d_6a60c1035973_ctl00_ctl05_ctl15_ctl00_ctl00_ctl04_ctl00_ctl00_TextField_inplacerte' style='min-height:42px' aria-labelledby='ctl00_m_g_74c26ddd_a3bd_4c7b_877d_6a60c1035973_ctl00_ctl05_ctl15_ctl00_ctl00_ctl04_ctl00_ctl00_TextField_inplacerte_label'  contentEditable='true' >
     <div class="ExternalClass67B0DBE162C14FC89FD1116AA392C2F3">
      000100 (<font color="#001965">R-U: </font><br />123456 (<font color="#001965">R-U: </font>Occupational)<br />654321 (<font color="#001965">R-U: </font>/* QBIQ document&#160;description&#160;not&#160;found&#160;in CM Tool. */)<br />
     </div>
    </div>
    <div style="clear:both;"></div>
  </div>
<span dir="ltr">

【问题讨论】:

  • 我看不到 textarea,您使用的是内容可编辑的 div - 不确定如何将其设为只读 - 删除 contentdeditable?但是你需要整理你的代码 - 跨度内不允许使用 div,字体标签已过时,不应使用
  • 你能用jQuery吗?
  • @HamzaAbdaoui 我可以试试
  • 试试这个$('#yourRichTextId').attr("contenteditable","false");
  • 你的意思是我这样做:function ReadOnlyRich() { $('#ctl00_m_g_74c26ddd_a3bd_4c7b_877d_6a60c1035973_ctl00_ctl05_ctl15_ctl00_ctl00_ctl04_ctl00_ctl00_TextField_inplace.");" }

标签: javascript sharepoint readonly


【解决方案1】:

您可以使用SPUtility 插件将字段设为只读或可编辑。

<script>window.SPUtility || document.write('\x3Cscript src="/sites/siteCollection/Style%20Library/Scripts/sputility.min.js" type="text/javascript">\x3C/script>')</script>

<script type="text/javascript">


    $(window).load(function () {

// to make a field read-only 
   SPUtility.GetSPFieldByInternalName('Internal_x0020_Name').MakeReadOnly();

// or to make it editable again
    SPUtility.GetSPFieldByInternalName('Internal_x0020_Name').MakeEditable();
    }); //close load

</script>

【讨论】:

  • 这对我不起作用,因为我在内部环境中工作,意味着我无法调用外部插件。
  • 我下载了插件并添加到 Style Library\Scripts 文件夹中,并将其包含在我的脚本中。你可以从第一行脚本中看到
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-18
  • 1970-01-01
  • 2023-02-06
  • 2023-03-31
  • 2014-04-22
  • 1970-01-01
相关资源
最近更新 更多