2016-02-11 39 views
-1

我有我的网站实时聊天开放时间,每个人都有自己的ID(数据聊天类别)。有一个类别ID我想要针对不同的开放时间。我努力编写一个IF语句来定位这个ID。我已经提取出需要编辑的JS。JS IF声明编号

这里是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 statetment太:

// 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? 
+0

'如果(ichatcategory == 407){设定特殊小时}其他{设定标准工时}'? –

+0

究竟是什么问题?你有错误吗? – Pointy

回答

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"; 
} 
+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.';