简体   繁体   English

在SharePoint中为SPF的NewForm添加JavaScript

[英]Add JavaScript to NewForm for SPList in SharePoint

I have a SPList in SharePoint that I want to edit the NewForm.aspx for. 我在SharePoint中有一个SPList,我想编辑NewForm.aspx。 I want to add a few JavaScripts as WebParts to the form programmatically. 我想以编程方式将几个JavaScripts作为WebParts添加到表单中。

How do I do that? 我怎么做?

Thanks for helping. 谢谢你的帮助。

Open the list in SharePoint designer in the "lists and libraries" section. 在“列表和库”部分中打开SharePoint设计器中的列表。 In the list designer view you will see a list of forms associated with the list, there will generally be a "NewForm.aspx" form listed. 在列表设计器视图中,您将看到与列表关联的表单列表,通常会列出“NewForm.aspx”表单。 Right click this and then select "Edit File in Advanced Mode" to expose the ASP .Net / HTML markup used for the form. 右键单击此选项,然后选择“在高级模式下编辑文件”以显示用于表单的ASP .Net / HTML标记。

Now, add your custom block within the page markup. 现在,在页面标记中添加自定义块。 I'd generally recommend that you find the asp:content element with id 'PlaceHolderMain'. 我通常建议你找到id为'PlaceHolderMain'的asp:content元素。 Add your script as the first element immediately after the content placeholder element opens like: 在内容占位符元素打开后立即添加脚本作为第一个元素,如:

<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
<script type='text/javascript' language='javascript'>
$(document).ready(function(e) { alert('my custom script has loaded'); });
</script>
..
.. Existing markup
..
</asp:Content>

My example above assumes you have jQuery present in your masterpage to display the message after the form has fully loaded. 我上面的示例假设您的母版页中存在jQuery,以在表单完全加载后显示消息。

If you don't want to (or can't) use SharePoint Designer you can put 如果您不想(或不能)使用SharePoint Designer,则可以使用

?ToolpaneView=2 ?ToolpaneView = 2

on the end of the URL to open the View/Edit/new form in design mode in the browser. 在URL的末尾,在浏览器中以设计模式打开View / Edit / new表单。

http://blog.pentalogic.net/2010/07/how-to-edit-list-forms-sharepoint-2010/ http://blog.pentalogic.net/2010/07/how-to-edit-list-forms-sharepoint-2010/

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

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