简体   繁体   English

如何通过更改菜单上的图像来突出显示当前页面?

[英]How can I higlight the current page by changing image on my menu?

This is one of the lines in my div nav: 这是我的div导航中的一行:

<a href="/Home/ShoppingCart"><img class="swap5" src="/Static/Images/Meny_normal_06.png"  alt="" /></a>

When someone click on this image they will get redirected to another page and I want this image to get swapped to my other image that is darker which highlights the current page. 当有人单击此图像时,他们将被重定向到另一页,我希望将此图像交换到我的另一张较暗的图像上,该图像突出显示当前页面。

在此处输入图片说明

to

在此处输入图片说明 <--- highlighted one that I want to change to while its current page <---在当前页面上突出显示了我要更改的内容

Here is my Jquery: 这是我的Jquery:

<script type="text/javascript">
        $(document).ready(function () {
            $('.swap5').click(function () {
                $(this).attr('src', '/Static/Images/Meny_clicked_01.png');


         });  
        });
</script

> >

I realized that this wont do it, beacuse the new image is gone by the time i get redirected to the other page.. 我意识到这不会做,因为新图像在我重定向到另一页时已经消失了。

How can I do this in a smooth way? 如何顺利进行? I am using MVC 3 btw 我正在使用MVC 3 btw

any kind of help is appreciated 任何形式的帮助表示赞赏

You can use plain javascript to achieve that. 您可以使用普通的javascript来实现。 Give the image element an id, let's say "me". 给图像元素指定一个ID,比如说“我”。 do something like document.getELmentById("me").setAttribute("src", "link to your other image"); 做类似document.getELmentById(“ me”)。setAttribute(“ src”,“链接到其他图像”)的事情; the

You can use a cookie in such cases.. As soon as the button is clicked you can store that info in a cookie. 在这种情况下,您可以使用cookie。单击该按钮后,您可以将该信息存储在cookie中。

In the next page check the cookie , if the value you expect was stored then replace the new image on the redirected page.. 在下一页中,检查cookie,如果存储了您期望的值,请在重定向的页面上替换新图像。

What about running this on the view you are redirecting to instead of the page you are redirecting from? 在要重定向到的视图而不是要重定向的页面上运行此命令怎么办?

<script type="text/javascript">
    $(document).ready(function () {
        $('.swap5').attr('src', '/Static/Images/Meny_clicked_01.png');
    });
</script>

Forget about jquery, i can do it using css. 忘了jQuery,我可以使用CSS做到这一点。

Use an .active class on the current page. 在当前页面上使用.active类。

Ex:- 例如:-

  1. Define a class 定义一个班级

    .active{background:url(/image/activemenu.jpg);} .active {background:url(/image/activemenu.jpg);}

  2. Use the class on the current page to highlight the nav. 使用当前页面上的课程突出显示导航。

    li> class="active"> a href="#"> ORDER /a> /li> li> class =“ active”> a href =“#”>订单/ a> / li>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在分页中突出显示当前页面菜单? - How do i keep my current page menu highlighted on pagination? 如何在不更改当前页面的情况下更改特定目录? - How can I change a specific directory without changing the current page? 我如何在我的引导程序中强调当前页面<nav></nav> - How i can underline the current page inside my bootstrap <nav> 如何自定义当前页面名称在菜单中的显示方式? - How do I customize the way a current page name looks in my menu? 如何将菜单滚动到菜单中的当前项目? - How can i scroll menu to current item in menu? 当我使用Javascript单击导航菜单链接时,如何更改页面的背景图像? - How can i change background image of the page when i click on navigation menu link using Javascript? 点击时如何创建图像并将其添加到页面? - How can i create and add an image to my page on click? 一旦用户向下滚动页面150px,如何将图像显示为菜单项? - How can I display an image as a menu item once the user has scrolled down the page 150px? 更改JSP页面中的下拉值后如何添加重新加载的gif图像? - How can I add reloading gif image after changing the dropdown value in JSP page? 如何防止我的菜单移动页面中的其他元素? - How can I keep my menu from moving other elements in the page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM