简体   繁体   English

如何将简单的jquery滑块添加到Sharepoint 2010 Web部件

[英]How to I add a simple jquery slider to a Sharepoint 2010 web part

I am trying to add the following code to the html of a sharepoint web part by clicking on "Edit HTML Source". 我试图通过单击“编辑HTML源代码”将以下代码添加到共享点Web部件的html中。 I am using a jquery plugin from the http://unslider.com/ website. 我正在使用http://unslider.com/网站上的jquery插件。 When I try to submit the code below into the sharepoint web part's html, I get the message: “the HTML source you entered might have been modified”. 当我尝试将下面的代码提交到共享点Web部件的html中时,我收到消息:“您输入的HTML源可能已被修改”。 As a result, all I see are two bulletted lines of text. 结果,我所看到的只是两行项目符号。 I'm fairly new to sharepoint and jquery. 我对sharepoint和jquery相当陌生。 Is making text or picture slideshow a lot more complicated in sharepoint than the code below would suggest? 在共享点中使文本或图片幻灯片显示比下面的代码更复杂吗?

<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="/wg/PayrollSolutions/SiteAssets/unslider-min.js"></script>

<script>
    $(function() { 
        $('.banner').unslider() 
    })
</script>

<div class="banner”>
    <ul>
        <li>Slider 1</li>
        <li>Slider 2</li>
    </ul>
</div>

Indeed, when you changed manually the html of a page, SharePoint'll often change the content and the output'll not be the same. 确实,当您手动更改页面的html时,SharePoint将经常更改内容,而输出将不会相同。

I think this article'll help you to understand what happens and what's your option : http://sharepoint.hannahswain.eu/2014/10/10/adding-a-code-snippet-to-page-content-on-sharepoint-2013/ 我认为本文将帮助您了解会发生什么以及您有什么选择: http : //sharepoint.hannahswain.eu/2014/10/10/adding-a-code-snippet-to-page-content-on-sharepoint -2013 /

The Embedded command and the text file should help you. 嵌入式命令和文本文件将为您提供帮助。

SharePoint will usually clean out any JavaScript added directly into the source of a content editor web part (although it'll leave in HTML and CSS). SharePoint通常会清除直接添加到内容编辑器Web部件源中的所有JavaScript(尽管它将保留在HTML和CSS中)。

Instead of adding the JavaScript directly into the source of a content editor web part, save it into a text file and upload it to a library on your site. 不要将JavaScript直接添加到内容编辑器Web部件的源中,而是将其保存到文本文件中并将其上载到站点上的库中。

Then, in your content editor web part, click the drop-down in the corner and choose the option to edit the web part properties. 然后,在内容编辑器Web部件中,单击角落的下拉菜单,然后选择选项以编辑Web部件属性。 The properties panel should appear on the side of the screen. 属性面板应显示在屏幕的侧面。

In the "Content Link" field in the web part properties, enter the URL of your uploaded text file. 在Web部件属性的“内容链接”字段中,输入您上载的文本文件的URL。 The content editor web part will then render whatever's in that text file, including HTML, CSS, and (most importantly) JavaScript. 然后,内容编辑器Web部件将呈现该文本文件中的所有内容,包括HTML,CSS和(最重要的是)JavaScript。

This has the added benefit of allowing you to use the same snippet of HTML/JS on multiple pages. 这具有允许您在多个页面上使用相同的HTML / JS代码段的附加好处。 If you need to make changes, you can change the contents of that file without having to edit the page(s) again. 如果需要进行更改,则可以更改该文件的内容,而无需再次编辑页面。

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

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