将 JavaScript 添加到 SharePoint 中的 SPList 的 NewForm
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10351162/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Add JavaScript to NewForm for SPList in SharePoint
提问by carruw
I have a SPList in SharePoint that I want to edit the NewForm.aspx for. I want to add a few JavaScripts as WebParts to the form programmatically.
我在 SharePoint 中有一个 SPList,我想为其编辑 NewForm.aspx。我想以编程方式将一些 JavaScript 作为 WebPart 添加到表单中。
How do I do that?
我怎么做?
Thanks for helping.
谢谢你的帮助。
回答by Brian Scott
Open the list in SharePoint designer in the "lists and libraries" section. 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. Right click this and then select "Edit File in Advanced Mode" to expose the ASP .Net / HTML markup used for the form.
在 SharePoint 设计器中的“列表和库”部分中打开列表。在列表设计器视图中,您将看到与该列表关联的表单列表,通常会列出一个“NewForm.aspx”表单。右键单击它,然后选择“在高级模式下编辑文件”以公开用于表单的 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'. Add your script as the first element immediately after the content placeholder element opens like:
现在,在页面标记中添加您的自定义块。我通常建议您找到 ID 为“PlaceHolderMain”的 asp:content 元素。在内容占位符元素打开后立即将您的脚本添加为第一个元素,如下所示:
<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 以在表单完全加载后显示消息。
回答by Ryan
If you don't want to (or can't) use SharePoint Designer you can put
如果您不想(或不能)使用 SharePoint Designer,您可以将
?ToolpaneView=2
?工具面板视图=2
on the end of the URL to open the View/Edit/new form in design mode in the browser.
在 URL 的末尾以设计模式在浏览器中打开查看/编辑/新建表单。
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/