2017-12-13 1 views
-3

내 웹 사이트의 모든 페이지에 회색 div (#showHideInfoXmas) 메시지가 있습니다. https://www.bagnboxman.co.uk/product/gusseted-clear-bottle-bags-94-diam-x-420mm/왜 내 "쿠키로 표시/숨기기"jquery 코드가 작동하지 않습니까?

작동하지 않습니다!

사용자가 메시지를 닫고 웹 사이트에 선택 사항을 기억하게하고 싶습니다.

쿠키 jquery 플러그인을 포함 시켰습니다. 포함 후에 스크립트를 옮기기까지했습니다.

$(function() { 
    $('#showHideInfoXmasButton').parent().toggle(!$.cookie('divHidden')); // Hide if cookie there 
    $('#showHideInfoXmasButton').click(function() { 
    $(this).parent().hide(); 
    $.cookie('divHidden', 'true'); // Remember it was hidden 
    }); 
}); 

<div id="showHideInfoXmas" style="display: block; background: rgba(0,0,0,0.15); clear: both; width: 100%; padding: 40px 20px; margin: 0 auto; text-align: center; max-width: 1000px; position: relative;"> 
    <div id="showHideInfoXmasButton" style="background: white; position: absolute; top: 10px; right: 10px; padding: 10px; color: red;">X</div> 
    <h2 style="color: red">IMPORTANT NEWS - Christmas closing, the weather and postage times</h2> 
    <p><b>Christmas opening times:</b> on Wednesday, December the 20th at 11am we are closed for our winter break, and re-opening on Wednesday the 3rd January 2018. Any orders placed after 9AM on December the 20th will not be processed until January 3rd at 
    the earliest.</p> 
    <p><b>Snowfall:</b> Due to the adverse weather conditions and the fact that it is our busiest time of the year, please be aware that any orders placed may take longer than usual to be dispatched. If your order is time-sensitive, please call us on 01295 
    788522. 
    </p> 
    <p><b>Stock levels:</b> Please note: as it is the busiest time of the year for us, our stock levels will be unpredictable, to avoid disappointment please get your orders in as soon as possible!</p> 
    <p><b>Postage:</b> As with any other online retailer, this time of the year sees extraordinary stresses on the national and world-wide postage and courrier network and your order may be subject to delays beyond of our control.</p> 
    <p>Rest assured; we are working very hard to ensure your orders are despatched as quickly as possible. Thank you for your understanding!</p> 
</div> 
+1

사이트에서 '$는 함수가 아닙니다'오류가 발생하면 jQuery가 포함되지 않은 것으로 보입니다. 또한 미래에 대한 모든 관련 코드는 * 질문에 배치해야합니다. –

+1

앞으로 가서 질문을 저장하려고 시도해보십시오. 귀하의 질문에 ** 관련 코드 **를 모두 포함하여 Rory가 위에 만든 점을 명심하십시오. –

+0

죄송합니다. Rory, thanks Master Yoda. 다음에 전체 코드가 포함됩니다. 코드는 형식을 지정하지 않았으므로 대신 요점을 사용했습니다. jquery가 포함되어 있습니다. 왜 그런 오류가 표시되는지 확실하지 않습니다. Rory? – tjcss

답변

0

진실은 정말 그것이 작동하지 않는 이유를 알고하지 않습니다,하지만 여기에 나를 위해 작동 코드입니다 :

<script type="text/javascript"> 
jQuery(document).ready(function($){ 

    if (typeof Cookies('divhideXMAS') === 'undefined'){ 
    //no cookie 
    jQuery('#showHideInfoXmas').show(); 
    } else { 
    } 
    jQuery('#showHideInfoXmasButton').click(function() { 
    jQuery(this).parent().hide(); 
    Cookies.set('divhideXMAS', true); 
    });  
}); 

나는 다음을 숨기 div는 기본적으로 css입니다.

관련 문제