简体   繁体   English

隐藏的JavaScript <li> 标记用户是否在线

[英]JavaScript to hide <li> tag if user is online

I have this JavaScript that works outside of the 我有这个JavaScript可以在

  • tag. 标签。

     <script type="text/javascript"> if (!window._laq) { window._laq = []; } window._laq.push(function(){liveagent.showWhenOnline('1234', document.getElementById('liveagent_button_online_1234')); liveagent.showWhenOffline('1234', document.getElementById('liveagent_button_offline_xxxx')); });</script> <script type='text/javascript' src='https://c.la2-c1cs-ord.salesforceliveagent.com/content/g/js/42.0/deployment.js'></script> <script type='text/javascript'> liveagent.init('https://d.la2-c1cs-ord.salesforceliveagent.com/chat', '12345', '123456'); </script> 

    I would like to show the li with the id of "menu2" only when the liveagent.showWhenOnline is true. 我只想在liveagent.showWhenOnline为true时显示id为“ menu2”的li。

    Here is the menu: 这是菜单:

     <div id='cssmenu' align="center"> <ul> <li><a href='#'><span>Admission Requirements</span></a></li> <li><a href='#'><span>Financial Aid/Scholarships</span></a></li> <li class='last'><a href='#'><span>FAQs</span></a></li> </ul> </li> <li class='has-sub'><a><span>Re-Enroll students </span></a></li> <li class='has-sub'><a><span>Parent Resources</span></a></li> <li class='has-sub'><a><span>Meet the Staff</span></a> <ul> <li><a href='#'><span>Admissions</span></a></li> <li><a href='#'><span>Financial Aid</span></a></li> <li class='last'><a href='#'><span>Student Ambassadors</span></a> </li> </ul> <li class='has-sub'><a href='#'><span>Request Information</span></a></li> <li class='menu2' style="border: 0px none; cursor: pointer" onclick="liveagent.startChat('1234')">menu 2</li> </div> 

    Let me know if that makes sense! 让我知道这是否有意义!

    Cheers, Rob 干杯,罗布

  • If you are getting the element by id, the current code won't work since you have set the class="menu2" and not id. 如果您通过id获取元素,则由于设置了class="menu2"而不是id,因此当前代码将无法工作。

    Try changing 尝试改变

    <li class='menu2' style="border: 0px none; cursor: pointer" onclick="liveagent.startChat('1234')">menu 2</li>
    

    to

    <li id='menu2' style="border: 0px none; cursor: pointer" onclick="liveagent.startChat('1234')">menu 2</li>
    

    If this doesn't work, share the code you have till now or a working codepen link. 如果这不起作用,请共享您到目前为止拥有的代码或有效的Codepen链接。

    声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

     
    粤ICP备18138465号  © 2020-2024 STACKOOM.COM