正如我可以做Bootstrap警报,按一个按钮来改变语言
问题描述:
我有一个问题,当访问者改变网络语言时,我尝试做一个警报,警报是创建但消失,因为这正在改变链接︰正如我可以做Bootstrap警报,按一个按钮来改变语言
?locale=es || ?locale=en || http://localhost:3000/pages/index?locale=en
默认是英文,但按下按钮,警报持续时间为0.5秒,并消失。
因为我可以让警报一直存在,直到你删除它?
注意:我使用Ruby On Rails。
我的按钮:
<li><a href="?locale=en" class="glyphicon glyphicon-share-alt" id="AlertEN"> <%= t('menuLen')%></a></li>
代码我警告:
<div class="container">
<center>
<div class="alert alert-success" id="successChangeEN" role="alert">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Success!</strong> Your Language is now English.
</div>
</center>
</div>
我的JS:
<script>
bootstrap_alert = function() {}
bootstrap_alert.warning = function(message) {
$('#alert_placeholder').html('<div class="alert alert-success"><a class="close" data-dismiss="alert">×</a><span>'+message+'</span></div>')
}
$('#AlertEN').on('click', function() {
bootstrap_alert.warning('You change the language success!');
});
</script>
我希望能回答,谢谢。
答
在这里你有使用cookie http://jsfiddle.net/0Lcofr6x/show/
源代码下面的例子:http://jsfiddle.net/0Lcofr6x/
URL不是因为事实小提琴变化的不接受假的查询字符串,但相信我,你导航到同一个页面(重装)。
$(document).ready(function() {
$('#AlertEN').attr('href', window.location.href);
bootstrap_alert = function() {}
bootstrap_alert.warning = function(message) {
$('#alert_placeholder').html('<div class="alert alert-success"><button class="close" data-dismiss="alert">×</button><span>'+message+'</span></div>');
$('#alert_placeholder .close').unbind("click");
$('#alert_placeholder .close').on('click', function() { $('#alert_placeholder').hide();
$('.alert-success').show();
});
}
$('#AlertEN').on('click', function() {
$.cookie("changed_locale", "You change the language success!");
});
$('.alert-success').hide();
if ($.cookie("changed_locale") != null)
{
bootstrap_alert.warning('You change the language success!');
}
$.removeCookie("changed_locale");
});
显然这是正确的,但不显示警报。 – AlexMp 2015-04-02 20:45:42
http://gyazo.com/b2b9ca2922379ab49f79312acabd65e8 这是网页按下按钮的截图 – AlexMp 2015-04-02 20:53:49