How to use jquery correctly in SharePoint Web Part - jquery doesn't always fire

前端 未结 4 1857
谎友^
谎友^ 2021-01-13 02:27

I\'m learning how to use jquery with SharePoint. My example draws a red box inside the Content Editor Web Part when a link is selected. My code works when the SharePoint p

4条回答
  •  我在风中等你
    2021-01-13 03:28

    The main problem with JavaScript code not consistenly firing when a page is loaded is because the entire page may not have finished loading and therefore the internal DOM may not have been completely constructed yet.

    The best way to fix this is to hook your code to the load or ready event.

    For example

    
    
    
    

    For detailed examples on how to use this in SharePoint, see http://www.muhimbi.com/blog/2009/07/massage-sharepoint-into-submission.html and http://www.muhimbi.com/blog/2009/07/automatically-add-search-as-you-type-to.html

提交回复
热议问题