通过右键单击更改完整日历中事件的背景颜色 - 不起作用
Changing the background color of an event in full calendar with right click - NOT WORKING
整个日历中的所有事件都由类 .fc-event 表示,当我想将右键单击功能绑定到 .fc-event 时,它不起作用,并且 JS 的阻止默认操作不会触发。所以我所做的是我用(document).bind 替换了它,这似乎确实触发了右键单击上下文菜单。但是,主要问题是当我在右键单击对象中单击红色或绿色时,它确实会触发警报。 但是颜色不会改变。我需要更改活动颜色的帮助。
问候
我在HTML中创建了一个自定义菜单:-
<ul class="custom-menu">
<li data-action="red" data-color="red">Red/Rouge</li>
<li data-action="green" data-color="green">Green/Verg</li>
</ul>
JS就是这样,显然我已经从不同的帖子中获得了帮助,但无法显示红色。
$(document).bind("contextmenu", function (event) {
event.preventDefault();
$(".custom-menu").data('event', $(this)).finish().toggle(100).
css({
top: event.pageY + "px",
left: event.pageX + "px"
});
});
// If the document is clicked somewhere
$(document).bind("mousedown", function(e) {
if (!$(e.target).parents(".custom-menu").length > 0) {
$(".custom-menu").hide(100);
}
});
// If the menu element is clicked
$("ul.custom-menu li").click(function() {
//var $event = $(this).parent().data('event');
// var color = $(this).attr('data-color') || 'lightblue'; // Default to light blue
// $event.css('background-color', color);
switch($(this).attr("data-action")) {
case "red":
var $event = $(".fc-event").attr('data-color');
$event.css('background-color',red);
// alert("first"); break;
case "green":
// alert("second"); break;
}
$(".custom-menu").hide(100);
});
CSS如下:-
#red{
background-color: red;
}
#green{
background-color: green;
}
.red{
background-color: red;
}
.green{
background-color: green;
}
.custom-menu{
display:none;
z-index:1000;
position:absolute;
overflow:hidden;
border:1px solid #CCC;
white-space: nowrap;
font-family: sans-serif;
background: #fff;
color:#333;
border-radius: 5px;
padding:0;
}
.custom-menu li{
padding:8px 12px;
cursor:pointer;
list-style-type:none;
transition:all .3s ease;
}
.custom-menu li:hover{
background-color: #DEF;
}
看来你有点困惑?我已经对您的代码进行了一些我认为应该的修复。
// If the menu element is clicked
$("ul.custom-menu li").click(function() {
// $event.css('background-color', color);
switch($(this).attr("data-action")) {
case "red":
// You're were getting the value of "data-color" and saving it into $event
// also you were assigning variable red, not the string
//var $event = $(".fc-event");
$(this).css("background-color","red");
// alert("first"); break;
case "green":
// alert("second"); break;
}
$(".custom-menu").hide(100);
});
相关文章:
- 点击AngularJS模态窗口捕捉背景事件
- 如何在Angular Material中的md背景后面接收ng点击事件
- 通过右键单击更改完整日历中事件的背景颜色 - 不起作用
- 绘制DOM元素:鼠标事件会被背景元素混淆
- 收听角度控制器中的phonegap背景事件
- 是否可以根据FullCalendar事件的标题指定其背景颜色
- 在点击和加载事件时播放暂停背景音频
- 背景事件的重叠行为与正常事件相同
- 更改 onclick 事件上的锚标记背景颜色
- 我在 标签中设置了背景图像,现在我想使用内联 CSS 在鼠标悬停事件上更改图像
- Javascript.使用鼠标悬停事件更改数组中 td 元素的背景颜色
- 剑道 UI 网格背景更改事件
- HTML - 如何在 OnClick 事件上更改按钮背景颜色
- 单击事件以更改单元格背景
- 了解HTML5视频何时可以在没有黑色背景的情况下播放的事件
- 如何在onmouseout事件中将背景颜色更改为透明
- 如何使用jquery获取点击事件中元素的背景图像
- 如何“;这个“;工作,在onclick事件的背景下?(Javascript)
- 如何在使用CSS'添加的图像上绑定点击事件;背景图像'属性
- 更快的滚动事件?-背景“跳跃”"在滚动