yii2 Fullcalendar - Why is alert for CalEvent working but not for updating innerHtml?

微笑、不失礼 提交于 2020-01-05 04:54:51

问题


I am using philippfrenzel/yii2fullcalendar and I want to show the event description.

when I am using the code:

<script>
var JSEventClick = (function(calEvent, jsEvent, view) {
   //  document.getElementsByClassName('.fc-title').innerHtml += 'calEvent.nonstandard.field1' ;
    alert(calEvent.title + ' -- ' + calEvent.nonstandard.field1);
});
</script>

it is working fine.

but when I am using:

<script>
var JSEventClick = (function(calEvent, jsEvent, view) {
     document.getElementsByClassName('.fc-title').innerHtml += calEvent.nonstandard.field1 ;
  //  alert(calEvent.title + ' -- ' + calEvent.nonstandard.field1);
});
</script>

or

<script>
(function(calEvent, jsEvent, view) {
     document.getElementsByClassName('.fc-title').innerHtml += calEvent.nonstandard.field1;
  //  alert(calEvent.title + ' -- ' + calEvent.nonstandard.field1);
});
</script>

also tried

<script>
var JSEventClick = (function(calEvent, jsEvent, view) {
    var myEvent = document.getElementsByClassName('.fc-title') ;
    var codeBlock = ( ' -- ' + calEvent.nonstandard.field1);
    myEvent.innerHtml += codeBlock;
  //  alert(calEvent.title + ' -- ' + calEvent.nonstandard.field1);
});
</script>

The contents of my html:

IPS Annual Day


回答1:


This is the line where you have the problem

document.getElementsByClassName('.fc-title').innerHtml += calEvent.nonstandard.field1;

getElementsByClassName will return an array-like object with all the tags which have the class you have specified. An array-like object doesn't have an innerHTML. The tags stored in the array-like object have an innerHTML. Also, I believe that you do not have an .fc-title class, you have an fc-title class instead, finally, make sure that innerHTML is typed properly. Proposed solution:

for (var element of document.getElementsByClassName('fc-title')) {
    element.innerHTML += calEvent.nonstandard.field1
}


来源:https://stackoverflow.com/questions/58048115/yii2-fullcalendar-why-is-alert-for-calevent-working-but-not-for-updating-inner

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!