问题描述
现在这是我的代码:
< script type =text / javascript>
$(document).ready(function(){
if($ .cookie('msg')== 0)
{
$('# myModal')。modal('show');
$ .cookie('msg',1);
}
});
< / script>
页面加载模型显示但是当我刷新它时会一直显示它应该只显示一次。 $ .cookie来自
更新:
这项工作:隐藏因某种原因无法运作
< script type =text / javascript>
$(document).ready(function(){
if($ .cookie('msg')== null)
{
$('#myModal')。 modal('show');
$ .cookie('msg','str');
}
else
{
$(div#myModal。 modal)。css('display','none');
}
});
< / script>
@SarmenB的更新适用于大多数浏览器(FF ,IE9)但不是IE8。
我修改了他的更新解决方案,让它在IE8中运行...
< script type =text / javascript>
$(document).ready(function(){
if($ .cookie('msg')== null)
{
$('#myModal')。 modal('show');
$ .cookie('msg','str');
}
else
{
$(div#myModal。 modal)。css('display','none');
}
});
< / script>
这是我提出的修改后的解决方案的工作原理是IE8 好吧:
< script type =text / javascript>
$(document).ready(function(){
if($ .cookie('msg')!= null&& $ .cookie('msg')!=)
{
$(div#myModal.modal,.modal-backdrop)。hide();
}
else
{
$(' #myModal')。modal('show');
$ .cookie('msg','str');
}
});
< / script>
基本上要让它在IE8中工作我必须反转if / else语句中的内容。
this is my code now:
<script type="text/javascript">
$(document).ready(function() {
if($.cookie('msg') == 0)
{
$('#myModal').modal('show');
$.cookie('msg', 1);
}
});
</script>
on page load the model shows but when i refresh it keeps showing which it should only show once. the $.cookie is from https://github.com/carhartl/jquery-cookie
update:
this worked: the 'hide' didnt work for some reason
<script type="text/javascript">
$(document).ready(function() {
if($.cookie('msg') == null)
{
$('#myModal').modal('show');
$.cookie('msg', 'str');
}
else
{
$("div#myModal.modal").css('display','none');
}
});
</script>
@SarmenB 's Update worked in most browsers (FF, IE9) but not IE8.
I modified his updated solution to get it to work in IE8...
This was @SarmenB 's solution:
<script type="text/javascript">
$(document).ready(function() {
if($.cookie('msg') == null)
{
$('#myModal').modal('show');
$.cookie('msg', 'str');
}
else
{
$("div#myModal.modal").css('display','none');
}
});
</script>
This is the modified solution I came up with that works is IE8 as well:
<script type="text/javascript">
$(document).ready(function() {
if($.cookie('msg') != null && $.cookie('msg') != "")
{
$("div#myModal.modal, .modal-backdrop").hide();
}
else
{
$('#myModal').modal('show');
$.cookie('msg', 'str');
}
});
</script>
Basicaly to get it to work in IE8 I had to reverse what was in the if/else statements.
这篇关于我怎样才能在twitter bootstrap中显示一次模态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!