javascript - 如何用Javascript让Javascript运行在页面的最后一个进程

标签 javascript jquery multithreading sharepoint sharepoint-2010

我遇到了一个麻烦,当页面加载时,我的 Javascript 会运行,并且 JS 日历会在我的 JS 之后加载。因此,我的 JS 不会影响 JS Calendar。

1.Page Loads

2.My JS runs

3.Something (Other JS) goes here

4.JS Calendar starts

我想要的是让我的JS在JS日历之后运行。有人建议我使用 on() 但我不知道这是最好的解决方案还是还有其他解决方案。

下面的 JSFIDDLE 在浏览器中运行良好,但不适用于 SharePoint 2010。

HTML:

<div id="AsynchronousViewDefault_CalendarView">
<div class="ms-acal-header">
<div>
    <table class="ms-acal-month">
    </table>
    <div class="ms-acal-vlink">
        <table>
            <tbody>
                <tr>
                    <td><a href="javascript:void(0)" title="Add" evtid="new_item">
                        <img border="0" src="/_layouts/images/caladd.gif">Add</a></td>
                </tr>
            </tbody>
        </table>
    </div>
</div>

Javascript:

$(document).ready(function () {
        var abc = $("#AsynchronousViewDefault_CalendarView").find('a[title="Add"][evtid="new_item"]').hover(
          function () {
              $(this).attr('href', 'http://share/Lists/Calendar.aspx?P=P1');
          }
        );
    });

JSFIDDLE: http://jsfiddle.net/nALMw/

我尝试使用 jQuery on() 但它不适用于我的 SharePoint 2010:

$( "#AsynchronousViewDefault_CalendarView div div table" ).on( "click", function() {
    var abc = $("#AsynchronousViewDefault_CalendarView").find('a[title="Add"] [evtid="new_item"]').hover(
        function () {
            $(this).attr('href', 'http://share/Lists/Calendar.aspx?P=P1');
        }
    );
});

$( "#AsynchronousViewDefault_CalendarView" ).on( "click", '.ms-acal-vlink' , function() {
    var abc = $("#AsynchronousViewDefault_CalendarView").find('a[title="Add"] [evtid="new_item"]').hover(
        function () {
            $(this).attr('href', 'http://share/Lists/Calendar.aspx?P=P1');
        }
    );
});

最佳答案

这是我的解决方案,如果它不适用于您的 SharePoint 或出现任何问题,请告诉我:-)。

$(document).on("click", "#AsynchronousViewDefault_CalendarView .ms-acal-vlink", function () {
        var find_aTag = $(("#AsynchronousViewDefault_CalendarView").find('a[title="Add"]'));
        find_aTag.attr("href", "http://share/Lists/Calendar.aspx?P=P1");
    });

MdMazzotti的方法

_spBodyOnLoadFunctionNames.push("spReady");

function spReady() {
  $('.s4-ba').on('click', '.ms-acal-item a', function(){ 
     console.log('clicked');  
  });
}

关于javascript - 如何用Javascript让Javascript运行在页面的最后一个进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23258664/

相关文章:

javascript - 我如何在 React 的 props 中应用 css 样式?

javascript - 防止隐藏的表单 div 在按下提交按钮时自动隐藏

java - 使用 onKeyReleased 事件创建搜索引擎的用途

php - Processmaker 中的 Jquery Ajaxing

python - 设置 Python Pub/Sub 异步拉取订阅者线程数

c++ - C++ 中的静态属性

javascript - 如何在 Puppeteer 中设置最大视口(viewport)?

c# - 每个服务器端事务的加载程序

javascript - 触发 ng-click 函数时更改 $scope 值

asp.net - 从服务器端的 asp.net 获取 jquery Accordion Pane 的事件索引?