# カレンダー表示時のタイトル文字色変更について

**URL:** <https://community.cybozu.dev/t/topic/2941>\
**Category:** kintone 開発相談\
**Created:** [2018 年 3 月 22 日午後 1:58 UTC](https://community.cybozu.dev/t/topic/2941 "2018-03-22T13:58:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Legacy\_Account1792](https://avatars.discourse-cdn.com/v4/letter/l/b5ac83/32.png) [@Legacy\_Account1792](https://community.cybozu.dev/u/Legacy_Account1792)\
**Post date:** [2018 年 3 月 22 日午後 1:58 UTC](https://community.cybozu.dev/t/topic/2941/1 "2018-03-22T13:58:06Z")

</div>

[https://developer.cybozu.io/hc/ja/community/posts/201107004-%E3%82%AB%E3%83%AC%E3%83%B3%E3%83%80%E3%83%BC%E4%B8%8A%E3%81%A7%E3%81%AE%E6%9B%B8%E5%BC%8F-%E6%96%87%E5%AD%97%E8%89%B2-%E5%A4%89%E6%9B%B4](https://developer.cybozu.io/hc/ja/community/posts/201107004-%E3%82%AB%E3%83%AC%E3%83%B3%E3%83%80%E3%83%BC%E4%B8%8A%E3%81%A7%E3%81%AE%E6%9B%B8%E5%BC%8F-%E6%96%87%E5%AD%97%E8%89%B2-%E5%A4%89%E6%9B%B4)

こちらを参考に作成してみたのですが、複数条件時の書き方がわかりませんでした。&nbsp;  
カレンダーのタイトルに「AA」を含む場合は赤、「BB」を含む場合は青、「CC」を含む場合は緑、それ以外は黒、としたいです。

(function() {&nbsp;  
“use strict”;

// カレンダービュー&nbsp;  
kintone.events.on(‘app.record.index.show’, function(event) {&nbsp;  
// カレンダービューの表示時にフィールド値の条件に応じて、文字色、フィールドの背景色を変更する&nbsp;  
var eles = document.getElementsByClassName(“cellitem-value-gaia”);&nbsp;  
for (var i = 0, il = eles.length; i \< il; i++) {&nbsp;  
var ele = eles[i];&nbsp;  
// eleに「〇〇」が含まれていたら、文字色を変更&nbsp;  
if (ele.textContent.indexOf(“AA”) \>= 0) {&nbsp;  
ele.style.color = ‘red’;&nbsp;  
ele.style.fontWeight = ‘bold’;&nbsp;  
}&nbsp;  
if (ele.textContent.indexOf(“BB”) \>= 0) {&nbsp;  
ele.style.color = ‘blue’;&nbsp;  
ele.style.fontWeight = ‘bold’;&nbsp;  
}&nbsp;  
if (ele.textContent.indexOf(“CC”) \>= 0) {&nbsp;  
ele.style.color = ‘green’;&nbsp;  
ele.style.fontWeight = ‘bold’;&nbsp;  
} else {&nbsp;  
ele.style.color = ‘black’;&nbsp;  
ele.style.fontWeight = ‘normal’;&nbsp;  
}&nbsp;  
}&nbsp;  
});&nbsp;  
})();

上記だと、一番最後の「CC」は条件が適用されるのですが、「AA」や「BB」は色がelseの場合と判断され、黒の表示になってしまいます。

初心者となり初歩的な質問となりますが、アドバイスいただけないでしょうか。&nbsp;  
よろしくお願いします。

---

<div class="post-metadata">

**Author:** ![Legacy\_Account531](https://avatars.discourse-cdn.com/v4/letter/l/dfb087/32.png) [@Legacy\_Account531](https://community.cybozu.dev/u/Legacy_Account531)\
**Post date:** [2018 年 3 月 23 日午前 1:07 UTC](https://community.cybozu.dev/t/topic/2941/2 "2018-03-23T01:07:10Z")

</div>

それぞれのif文が独立しているため、AAが含まれていてredになってもCCが含まれていないのでblackに上書きされてしまっています。  
下記のようにelseで繋げれば期待されている動きになるかと思います。

if (ele.textContent.indexOf(“AA”) \>= 0) {&nbsp;  
ele.style.color = ‘red’;&nbsp;  
ele.style.fontWeight = ‘bold’;&nbsp;  
} else&nbsp;if (ele.textContent.indexOf(“BB”) \>= 0) {&nbsp;  
ele.style.color = ‘blue’;&nbsp;  
ele.style.fontWeight = ‘bold’;&nbsp;  
} else&nbsp;if (ele.textContent.indexOf(“CC”) \>= 0) {&nbsp;  
ele.style.color = ‘green’;&nbsp;  
ele.style.fontWeight = ‘bold’;&nbsp;  
} else {&nbsp;  
ele.style.color = ‘black’;&nbsp;  
ele.style.fontWeight = ‘normal’;&nbsp;  
}&nbsp;

---

<div class="post-metadata">

**Author:** ![Legacy\_Account1792](https://avatars.discourse-cdn.com/v4/letter/l/b5ac83/32.png) [@Legacy\_Account1792](https://community.cybozu.dev/u/Legacy_Account1792)\
**Post date:** [2018 年 3 月 23 日午前 2:33 UTC](https://community.cybozu.dev/t/topic/2941/3 "2018-03-23T02:33:44Z")

</div>

takasakaiさん

教えていただきありがとうございます。

それぞれをelse if でつなげることにより、期待する動きになりました！！

ありがとうございました。
