Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何添加';don';不要再次显示此消息';是否使用本地存储?_Javascript_Jquery_Twitter Bootstrap 3 - Fatal编程技术网

Javascript 如何添加';don';不要再次显示此消息';是否使用本地存储?

Javascript 如何添加';don';不要再次显示此消息';是否使用本地存储?,javascript,jquery,twitter-bootstrap-3,Javascript,Jquery,Twitter Bootstrap 3,我有一个引导警报 <div class="checkbox"> <label> <input type="checkbox"> Don't show this again! </label> </div> 如果存在cookie,则隐藏消息$。隐藏方法 使用解决方案更新 var oldBrowser = $.browser.msie && parseInt($.browser.versio

我有一个引导警报

<div class="checkbox">
    <label>
        <input type="checkbox"> Don't show this again!
    </label>
</div>
如果存在cookie,则隐藏消息
$。隐藏方法

使用解决方案更新

var oldBrowser = $.browser.msie && parseInt($.browser.versionNumber) < 9;

//message is dismissed via storage
var dissmissed = amplify.store("DoNotShowMessageAgain");

// if oldbrowers and not dismissed
if (oldBrowser && !dissmissed) {
     $( "#browserAlert" ).show();
}


// Don't show message again
$('#browserAlert .close').click(function(){
if ($('.checkbox input').is(':checked')) {
     amplify.store( "DoNotShowMessageAgain", true );
 }
}) 
var oldBrowser=$.browser.msie&&parseInt($.browser.versionNumber)<9;
//消息通过存储器被解除
var dissmissed=amplify.store(“不再显示消息”);
//如果你是老布朗而不是被解雇
如果(旧浏览器&&!丢失){
$(“#browserAlert”).show();
}
//不再显示消息
$('#browserAlert.close')。单击(函数(){
如果($('.checkbox input')。是(':checked')){
amplify.store(“不再显示消息”,true);
}
}) 

我的建议是使用HTML5的本地存储。它的目的是为浏览器提供一种在会话之间持久保存数据的现代方法,而不会过期:

function localStorageAvailable() {
    if (typeof(Storage) !== "undefined") {
        return true;
    }
    else {
        return false;
    }
}

$('#checkbox').click(function(){
    if ($('#checkbox').attr('checked')) {
        if (localStorageAvailable())
            localStorage.DoNotShowMessageAgain = "true";
    }
}) 
然后,当页面准备就绪时,您需要检查并从过去保存的体验中恢复功能:

if (localStorageAvailable()) {
    if (localStorage.DoNotShowMessageAgain && localStorage.DoNotShowMessageAgain === "true") {
        // user doesn't want to see the message again, so handle accordingly
    }
};

有关HTML5本地存储的更多信息,请参阅本主题。

是-您可以使用Cookie。您可能希望在cookie分配代码上花费多一点时间,以确保现有cookie不会被覆盖。本地存储是否适用于下面的IE9、IE8。消息实际上是为了查看浏览器兼容图表,因为他们使用不兼容的旧浏览器访问网站。HTML5 web存储在IE8及以上版本中提供:好的,谢谢,我已经用我的进度更新了问题。。它是有效的。但是如果我遗漏了什么,请告诉我?看起来这已经足够了,但是说实话,我直接使用web存储而不是JS。但它似乎解决了同样的问题,所以如果您的测试证明成功,它看起来不错。谢谢。好像这个应用已经有了一个新的JS,所以我用了它。但我确实需要学习如何直接使用它。
function localStorageAvailable() {
    if (typeof(Storage) !== "undefined") {
        return true;
    }
    else {
        return false;
    }
}

$('#checkbox').click(function(){
    if ($('#checkbox').attr('checked')) {
        if (localStorageAvailable())
            localStorage.DoNotShowMessageAgain = "true";
    }
}) 
if (localStorageAvailable()) {
    if (localStorage.DoNotShowMessageAgain && localStorage.DoNotShowMessageAgain === "true") {
        // user doesn't want to see the message again, so handle accordingly
    }
};