2017-12-13 5 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

申し訳ありませんロリー、ありがとうマスターヨーダ。次回は完全なコードが含まれます。コードはフォーマットしないので、要点を代わりに使用します。 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です。

関連する問題