简体   繁体   English

Office 365,Sharepoint,HTML列表 <h1> 内容

[英]Office 365, Sharepoint, List of Html <h1> contents

I am new to Sharepoint (365) and try to make some Wiki-Webpage. 我是Sharepoint(365)的新手,并尝试制作一些Wiki-Webpage。 But there is no Contents overview like on Wikipedia or Mediawiki. 但是没有像Wikipedia或Mediawiki上的目录概述。 Since Sharepoint doesn't know PHP I try to create some content-menu in Javascript. 由于Sharepoint不了解PHP,因此我尝试使用Javascript创建一些内容菜单。

When I add Javascript into the source code of my current webpage, sharepoint removes it with some warning information. 当我将Javascript添加到当前网页的源代码中时,sharepoint会使用一些警告信息将其删除。 The warning wants me to use the webpart option. 警告要我使用webpart选项。

Now I have added the js-code in the Webpart, but it looks like the script can't do what I want because it is not included in the site HTML. 现在,我在Webpart中添加了js代码,但是该脚本似乎无法执行我想要的操作,因为该脚本未包含在站点HTML中。

When I test the js-code with some alert("test"); 当我用一些alert(“ test”)测试js代码时; I get a reaction. 我得到反应。 But when I try to get some html content with document.getElementsByTagName('h2'); 但是当我尝试使用document.getElementsByTagName('h2');获取一些html内容时; it does nothing. 它什么也没做。

Is Javascript the correct way to make some 'content'-overview by lookup the html 'h1' tags? Javascript是通过查找html'h1'标签进行“内容”概述的正确方法吗? Normaly I would use PHP but Sharepoint doesn't know the language. 通常,我会使用PHP,但是Sharepoint不知道该语言。 What is the server-sided language of Sharepoint? Sharepoint的服务器端语言是什么?

Yes you can use Content Editor Webpart to add your javascript. 是的,您可以使用Content Editor Webpart添加您的JavaScript。

Steps to add Content Editor Webpart 添加Content Editor Webpart步骤

  1. Edit that page 编辑该页面
  2. click on Add a WebPart 单击添加WebPart
  3. select Media and Content 选择媒体和内容

Modify your script like this:- 像这样修改脚本:

    <script type ="text/javascript">
window.onload=function()
{
 var getbyid = document.getElementById("mydiv1");
 alert(getbyid.getElementsByTagName("h1")[0].firstChild.data); 
};
</script>
<div id="mydiv1"> 
<h1>Heading 1</h1> 
<p>Some text for Heading 1.</p> 
<h2>Heading 2</h2> 
<p>Some text for Heading 2.</p>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM