[英]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:- 例如:-
Define a class 定义一个班级
.active{background:url(/image/activemenu.jpg);} .active {background:url(/image/activemenu.jpg);}
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.