我正在编写一个检测语言的简单脚本,然后相应地更改两个菜单项的可见性。 (测试网站:women.semeasy.com)
这是我写的代码:
<script type="text/javascript">
jQuery(document).ready(function(e) {
if (jQuery('#slogan').html() == 'Centro de Información'){
jQuery('#menu-item-862').css('display', 'block !important');
jQuery('#menu-item-743').css('display', 'none !important');
};
});
</script>
它应该做的是检查口号,看它是否是西班牙语。如果是,则隐藏“En Espanol”链接并显示“In English”一个......
非常直接,但它不起作用:(非常感谢任何建议!
答案 0 :(得分:2)
为您的目的使用适当的方法
jQuery('#menu-item-862').show();
jQuery('#menu-item-743').hide();
答案 1 :(得分:1)
您不能将!important
与jquery一起使用。你需要删除它。如果您需要!important
,请创建一个包含重要的类,然后使用addClass
。
答案 2 :(得分:0)
假设您的代码是您可以做的最好的(有更强大的方法来检测区域语言),请考虑更改
jQuery('#slogan').html() == 'Centro de Información')
进入
jQuery.trim(jQuery('#slogan').text()) === 'Centro de Información')
我相信它更可靠。