按 ID 的 JS IF 语句

JS IF statement by ID

本文关键字:IF 语句 JS ID      更新时间:2023-09-26

我的网站上都有实时聊天的开放时间,每个都有自己的ID(数据聊天类别)。我想定位一个类别 ID,以提供不同的开放时间。我正在努力编写一个 IF 语句来针对此 ID。我已经提取了需要编辑的 JS。

以下是带有 ID 的 HTML:

<div class="live_chat" data-chat-interface="toms" data-chat-category="407" data-chat-product="370"></div>

这是参数:

var iChatCategory = $(this).attr('data-chat-category');

这是我无法正确处理或也需要添加 IF 状态的一点:

// Show correct opening times for all iChatCategorys except 407
var sOpeningTimes = (sChatInterface.indexOf("toms") >= 0) ? 'Live chat is open Monday to Thursday from 8:30am to 5:30pm, Friday 8:30am to 5pm.' : 'Live chat is open Monday to Friday from 8am to 8pm, Saturday 8am to 6pm.';
// Show correct opening times for iChatCategorys 407 only goes under here?
 var sOpeningTimes = "";
 if(iChatCategory !== "407") {
 sOpeningTimes = (sChatInterface.indexOf("toms") >= 0) ? 'Live chat is open Monday to Thursday from 8:30am to 5:30pm, Friday 8:30am to 5pm.' : 'Live chat is open Monday to Friday from 8am to 8pm, Saturday 8am to 6pm.';
 } else {
  sOpeningTimes = "message for iChatCategory 407";
 }

只需编辑三元中的条件即可。

// Show correct opening times for all iChatCategorys except 407
var sOpeningTimes = (iChatCategory != 407) ? 'Live chat is open Monday to Thursday from 8:30am to 5:30pm, Friday 8:30am to 5pm.' : 'Live chat is open Monday to Friday from 8am to 8pm, Saturday 8am to 6pm.';