ID的JS IF语句

时间:2016-02-11 15:10:17

标签: javascript

我的网站上有实时聊天时间,每个时间都有自己的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?

2 个答案:

答案 0 :(得分:1)

只需在三元组中编辑条件。

// 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.';

答案 1 :(得分:1)

 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";
 }