正如我可以做的 Bootstrap 提醒,按一个按钮来改变语言
As I can do Bootstrap alert, pressing a button to change language
我有一个问题,我尝试在访问者更改网络语言时发出警报,警报已创建但消失了,因为这正在通过以下方式更改 link:
?locale=es || ?locale=en || http://localhost:3000/pages/index?locale=en
默认为英文,但按下按钮,警报持续 0.5 秒后消失。
我可以让警报一直保留到您删除它吗?
注意:我在 Rails.
上使用 Ruby
我的按钮:
<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 没有改变,因为 fiddle 不接受虚拟查询字符串,但请相信我,您正在导航到同一页面(重新加载)。
$( 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");
});
我有一个问题,我尝试在访问者更改网络语言时发出警报,警报已创建但消失了,因为这正在通过以下方式更改 link:
?locale=es || ?locale=en || http://localhost:3000/pages/index?locale=en
默认为英文,但按下按钮,警报持续 0.5 秒后消失。
我可以让警报一直保留到您删除它吗?
注意:我在 Rails.
上使用 Ruby我的按钮:
<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 没有改变,因为 fiddle 不接受虚拟查询字符串,但请相信我,您正在导航到同一页面(重新加载)。
$( 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");
});