我的目标是绑定到页面上的许多元素(使用on()),然后在单击后从特定元素(使用off())取消绑定.
$(document).on({
mouseenter: enter,
mouseleave: leave,
mousedown: down,
mouseup: up,
click: click
}, ".up_side .thumbsUp");
Run Code Online (Sandbox Code Playgroud)
on()函数运行良好,但我无法弄清楚如何使用off()从被点击的元素取消绑定.
var click = function() {
var thumbsUp = $(this);
var successCallback = function(data) {
// This is where I need to unbind the clicked element
$(thumbsUp).off({
mouseenter: enter,
mouseleave: leave
});
}
$(this).castVote(direction, modelName, modelId, successCallback, errorCallback);
}
Run Code Online (Sandbox Code Playgroud)
谢谢!!!
使用.data()存储标志并在执行代码之前检查标志.这似乎是一种解决方法,使代码更加脆弱.如果有人找到更好的方法,请回复.谢谢!
$(document).on({
mouseenter: function(){
if ($(this).data("submitted") != true)
{
$(this).css("cursor", "pointer");
$(this).css("backgroundPosition", "-48px");
}
},
mouseleave: function(){
if ($(this).data("submitted") != true)
{
$(this).css("backgroundPosition", "0px"); …Run Code Online (Sandbox Code Playgroud) 我正在尝试查找给定月份和年份的每周周期。日期应从星期一开始,到星期日结束。如果该月的 1 号是星期日(2011 年 5 月之前),则它应该是第一个元素。
\n\n2011年5月
\n\n2012年9月
\n\n我使用此函数来计算两个日期的周数 - 即该月的第一天和该月的最后一天。
\n\npublic function getWeekNumbers($startDate, $endDate)\n{\n $p = new DatePeriod(\n new …Run Code Online (Sandbox Code Playgroud)