Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.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
Twitter bootstrap 使用Twitter引导,你如何;记住;用户操作?_Twitter Bootstrap - Fatal编程技术网

Twitter bootstrap 使用Twitter引导,你如何;记住;用户操作?

Twitter bootstrap 使用Twitter引导,你如何;记住;用户操作?,twitter-bootstrap,Twitter Bootstrap,我正在使用引导警报框,希望这些框“记住”它们是否已关闭。这样,当用户登录到成员区域并关闭警报时;下一次他们访问该站点时,警报仍将消失 有没有办法做到这一点 <div class="alert-message success" data-alert="alert"> <a class="close" data-dismiss="alert" href="#">&times;</a>When I click &times; I'd like thi

我正在使用引导警报框,希望这些框“记住”它们是否已关闭。这样,当用户登录到成员区域并关闭警报时;下一次他们访问该站点时,警报仍将消失

有没有办法做到这一点

<div class="alert-message success" data-alert="alert">
<a class="close" data-dismiss="alert" href="#">&times;</a>When I click &times; I'd like this to never appear again.</div>

当我点击×;我希望这个再也不会出现了。

您可能必须将该首选项存储在cookie或服务器本身中。可以在中找到好的阅读资料

用于存储cookies 基本上,您需要做的是围绕代码实现javascript。为了简单起见,我使用jQuery和jQuery cookie插件

// jQuery pulled from Google CDN
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
// jQuery cookie plugin. You will have to download it on your own: https://github.com/carhartl/jquery-cookie
<script src="/path/to/jquery.cookie.js"></script>
// jQuery action here
<script>
    function runOnLoad(){
        if($.cookie('alert-box') == null) {
            $.cookie('alert-box', 'open', { expires: 7 });
        } else if($.cookie('alert-box') == 'close') {
            $(".close").hide();
        }

        // php psuedo code here (if you are using the server option)
        <?php
            if(check database for hide option == true){
                echo '$(".close").hide();
            }
        ?>
    }
    function hideMe(){
        $.cookie('alert-box', 'close', {expires:7 });
        $(".close").hide();
    }
</script>

<body onload="runOnLoad()">
    <div class="alert-message success" data-alert="alert">
        <a class="close" data-dismiss="alert" href="hideMe.php" onclick="hideMe()" >&times;</a>When I click &times; I'd like this to never appear again.
    </div>
</body>
//从Google CDN中提取jQuery
//jquerycookie插件。您必须自行下载:https://github.com/carhartl/jquery-cookie
//jQuery操作在这里
函数runOnLoad(){
if($.cookie('alert-box')==null){
$.cookie('alert-box','open',{expires:7});
}如果($.cookie('alert-box')=='close'),则为else{
$(“.close”).hide();
}
//php psuedo代码(如果使用服务器选项)

我为我的网站写了一个基本的解决方案,很好地满足了我的需求:

  • 我已经使用了等待DOM上存在警报元素
  • 脚本正在alert div上查找具有唯一值的属性数据id。这将稍后用于存储在cookie或db上,并且可以是可选的
  • 我已经使用cookies插件来存储关闭的警报数据id,这个唯一的值可以是可选的,并且可以直接设置为html属性。即使存储方法可以改进很多(比如使用json将多个警报作为对象存储在一个cookie中),这也可以满足我的需要
DOM就绪后要使用的JS:

//bind to close alerts link
$('.alert a.close').livequery(function()
{
    $(this).bind('click', function()
    {
        var id = $(this).parents('.'+$(this).data('dismiss')).data('id');

        if(id)
        $.cookie('alert-'+id, 'closed', { path: '/' });
    });
});

//hide closed alerts
$('.alert').livequery(function()
{
    var id = $(this).data('id');

    if($.cookie('alert-'+id))
    $(this).hide();
});

我真的没有Javascript方面的经验-所以我发现这个线程对于我的经验水平来说太模糊了。不过还是要谢谢你。当涉及到破解代码(几乎任何语言)时,我都很有能力我可以用基础知识来完成。我正在用php/mysql、html/css/javascript从头开始编写一个网站。我没有足够的经验来学习这些基础知识并调整我的代码。嗨,我已经用伪代码更新了答案。希望它能帮助你理解链接线程中提供的两个解决方案。