在回发后保存jquery之前状态的问题 [英] Problem with saving jquery previous state after postback

查看:70
本文介绍了在回发后保存jquery之前状态的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,这是我的问题,继承人我的HTML



Ok heres my problem,heres my html

<ul>
     <li class="current"><a href="Default.aspx" id="1">1</a></li>
     <li ><a href="Default.aspx" id="2">2</a></li>
     <li ><a href="Default.aspx" id="3">3</a></li>
 </ul>





我想要的第一个更改c上的列表项的类舔,我设法用下面的jquery代码:





1st i wanted to change class of list item on click, which i managed to do with jquery code below:

<script type="text/javascript">
           $(function () {
               $('li').click(function () {
                   $("li.current").removeClass("current")
                   $(this).addClass('current');
               });
           });
   </script>





我想要的是从一个li中删除当前的类并将其添加到被点击的li上。

但是当我点击链接时出现问题...当前课程返回默认位置(第一个li)。

有没有办法在点击之前继续上课链接???

-------------------------------------- -------------------------------------------------- -------



继承人我想做的事情:

我有一个导航,一旦链接被点击我需要将用户重定向到其他页面,但我想保存已点击的li中的类并将其从其他li中删除(例如,当用户单击时,类当前的默认位置在第一个LI(Home)上其他链接(比方说健康)我需要在其他页面上重定向他,从第一个LI(Home)删除类,并将其分配给被点击的li(健康))我希望你现在明白我的整个问题。一旦重定向发生就会出现问题......顺便说一句,这段代码在我的母版页上...





继承人我的HTML:





All i wanted was to remove current class from one li and add it on li that was clicked..
but problem happens when i click on link...current class goes back on default spot (1st li).
Is there a way to keep class on li it was on before clicking on link???
-----------------------------------------------------------------------------------------------

Heres what i want to do:
I have a navigation, once link is clicked i need to redirect user to other page, but i want to save class in li that was clicked and remove it from other li (for example default place of class Current is on first LI (Home), when user click on other link (lets say Health) i need to redirect him on other page, remove class from first LI(Home), and assign it to li that was clicked(Health)) i hope u understand my whole problem now. Problem occurs once redirect happens...btw this code is on my master page...


Heres my HTML:

<ul>

                    <li class="current"><a href="Category.aspx">Home</a></li>

                    <li><a href="Product.aspx?CategoryID=39">Health</a>

                        <ul>
                            <li><a href="Product.aspx?CategoryID=1">Product 1 shown once u hover li in navigation</a></li>
                            <li><a href="Product.aspx?CategoryID=2">Product 2 shown once u hover li in navigation</a></li>
                            <li><a href="Product.aspx?CategoryID=3">Product 3 shown once u hover li in navigation</a></li>
                        </ul>

                    </li>
                    <li><a href="Product.aspx?CategoryID=40">Childrens</a>
                        <ul>
                            <li><a href="Product.aspx?CategoryID=21">Product 1 shown once u hover li in navigation</a></li>
                            <li><a href="Product.aspx?CategoryID=22">Product 2 shown once u hover li in navigation</a></li>
                            <li><a href="Product.aspx?CategoryID=23">Product 3 shown once u hover li in navigation</a></li>
       
                           
                    <li><a href="Product.aspx?CategoryID=41">Women's health</a>
                         <ul>
                            <li><a href="Product.aspx?CategoryID=26">Product 1 shown once u hover li in navigation</a></li>
                            <li><a href="Product.aspx?CategoryID=27">Product 2 shown once u hover li in navigation</a></li>
                      
</ul>





上面的Jquery代码删除了li的类并将其分配给其他,但一旦发生重定向它的丢失...任何想法如何使其工作?



That Jquery code above removes class of an li and assing it to other, but once redirect occurs its lost...Any ideas how to make it work?

推荐答案

(function(){
(function () {


('li' ).click(function(){
('li').click(function () {


(li.current)。removeClass(current)
("li.current").removeClass("current")


这篇关于在回发后保存jquery之前状态的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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