单击元素时更改URL和CSS [英] Change URL AND CSS when an element is clicked

查看:49
本文介绍了单击元素时更改URL和CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我的网站上有几个页面,我在其中使用PHP在页面中包含内容,并使用jQuery通过将CSS中的显示设置为无"或阻止"在内容之间切换".但是,我正在努力使其与菜单一起在主页上运行.因此,当用户单击适当的链接时,我需要将页面更改为包含内容的页面,同时还要应用适当的CSS来显示适当的内容.到目前为止,我(URL被阻止):

Basically, I have several pages on my website where I am using PHP to include the content in the page, and using jQuery to "switch" between the content by setting the display in CSS to "none" or "block". However, I am struggling to get it to work in the main page with the menu. So I need when the user clicks on the appropriate link, the page will change to the page where the content is contained, but also apply the appropriate CSS as to display the appropriate content. So far I have (URL blocked out):

<script type="text/javascript">
    $(document).ready(function(){
        $('#ourMissionMenu').click(function() {
                window.location = 'http://beta.***.com/aboutUs.php';
                $('#rightReplace').css({
                  "display":"none"
                  });
                  $('#ourHistory').css({
                  "display":"none"
                  });
                  $('#meetTeam').css({
                  "display":"none"
                  });
                  $('#communityOutreach').css({
                  "display":"none"
                  });
                  $('#connectUs').css({
                  "display":"none"
                  });
                  $('#blog').css({
                  "display":"none"
                  });
                   $('#ourMission').css({
                  "display":"block"
                  }); 
        });
});


</script>

推荐答案

如果更改窗口的位置,则当前页面中的所有javascript都将停止.您不能期望一个页面中的javascript控制另一个页面上的内容.这将是大规模的安全违规行为.

If you change the location of the window, all javascript from the current page will cease. You cannot expect javascript from one page to control content on another page. This would be a massive security violation.

您需要JavaScript才能在"aboutUs.php"上运行,或将aboutUs内容动态加载到当前页面中.或者,更好的是,首先让aboutUs.php拥有正确的CSS.

You need the javascript to run on "aboutUs.php", or dynamically load the aboutUs content into your current page. Or, better still, have aboutUs.php have the correct css in the first place.

这篇关于单击元素时更改URL和CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆