简体   繁体   中英

Add JavaScript to NewForm for SPList in SharePoint

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.

How do I do that?

Thanks for helping.

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.

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:

<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.

If you don't want to (or can't) use SharePoint Designer you can put

?ToolpaneView=2

on the end of the URL to open the View/Edit/new form in design mode in the browser.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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