我遇到了一个麻烦,当页面加载时,我的 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/