我正在使用fullcalendar。目前我正在开发可拖动的事件,但我想根据事件的ID设置背景颜色。
Html(可拖动事件部分)
<div id='external-events'>
<h4>Versleepbare afspraak</h4>
<? if ($colors !=null) : foreach($colors as $row) : ?>
<div class='external-event' id="<?= $row->id; ?>" style="background-color:<?= $row->colortag; ?>" ><?= $row->soort; ?></div>
<? endforeach;endif; ?>
<input type='checkbox' id='drop-remove' /> <label for='drop-remove'>verwijder afspraak na plaatsen</label>
</div>
fullcalendar.js(droppable事件部分):
droppable: true,
drop: function(event, start, allDay, delta) {
var title = $("div.external-event").text();
var start = $.fullCalendar.formatDate(event, "yyyy-MM-dd HH:mm:ss");
var originalEventObject = $(this).data('eventObject');
var color = $('#id').css('background-color') ;
var copiedEventObject = $.extend({}, originalEventObject);
console.log(event);
copiedEventObject.start = start;
copiedEventObject.allDay = allDay;
$('#calendar').fullCalendar('renderEvent', copiedEventObject, true);
if ($('#drop-remove').is(':checked')) {
$(this).remove();
}
console.log(start);
$.ajax({
url: "../testcalendar/fullcalendar/add_events.php",
data: 'title='+ title +'&start='+ start +'&idWerknemer='+ '20' +'&color='+ color,
type: "POST",
});
},
add_events.php:
<?php
// Values received via ajax
$title = $_POST['title'];
$start = $_POST['start'];
$end = $_POST['end'];
$color = $_POST['color'];
$idWerknemer = $_POST['idWerknemer'];
// connection to the database
try {
$bdd = new PDO('mysql:host=localhost;dbname=blackboks-calendar', 'root', 'root');
} catch(Exception $e) {
exit('Unable to connect to database.');
}
// insert the records
$sql = "INSERT INTO evenement (title, start, end, idWerknemer, color) VALUES (:title, :start, :end, :idWerknemer, :color)";
$test = "INSERT INTO evenementontvanger (idWerknemer) VALUES (:idWerknemer)";
$q = $bdd->prepare($sql);
$qo = $bdd->prepare($test);
$q->execute(array(':title'=>$title, ':start'=>$start, ':end'=>$end, ':idWerknemer'=>$idWerknemer, ':color'=>$color));
$qo->execute(array(':idWerknemer'=>$idWerknemer));
?>
我想根据id设置颜色。数据库中的id目前是1,2,3,但我如何根据id设置颜色?因为即时通讯使用foreach循环
答案 0 :(得分:0)
我不认为我理解这个问题。当然你可以在你的CSS中使用#1{ background-color #F00;}
设置颜色,但这可能不是你要问的那样?...