English 中文(简体)
如何储存先前被点击的碎片
原标题:How to store the previous clicked element in jquery
  • 时间:2009-12-02 08:44:47
  •  标签:
  • jquery

我有一张桌子,有以下几行:

        <table>
            <tr>
                <td><div>Suresh</div></td>
                <td><div>Ramesh</div></td>
                <td><div>Sachin</div></td>
            </tr>
            <tr>
                <td><div>Rahul</div></td>
                <td><div>Shiv</div></td>
                <td><div>Shyam</div></td>
            </tr>
             <tr>
                <td><div>Tandav</div></td>
                <td><div>Kiran</div></td>
                <td><div>Radha</div></td>
            </tr>
             <tr>
                <td><div>Pankaj</div></td>
                <td><div>Jiten</div></td>
                <td><div>Sandeep</div></td>
            </tr>
      </table>
    </div>

档案

.coloradd
{
   background-color:orange;
}

Check = function()
{

    $( tr ).click(function(e){
        if(e.ctrlKey)
        {        
            $(this).addClass("coloradd");
        }
        else if(e.shiftKey)
        {
               //Code to be written to select multiples rows. 
        }
        else
        {
            $( tr ).removeClass("coloradd");
            $(this).addClass("coloradd");
        }
    });

};

在我发布控制钥匙时,我可以选择多行,在背景颜色的帮助下显示。

但是,当我选择一行时,当我点击另一行时,在轮到一角时,需要强调这两个行之间的所有行踪(应当适用特别安全局)。 是否有办法这样做?

最佳回答
if(e.shiftKey)
{
   // check previous selected row
   if( $( tr.coloradd:first ).length == 1)
   {
     // okay, now check prev selected index
     var previndex = $( tr ).index($( tr.coloradd:first ));

     // compare with current selected index
     var currindex = $( tr ).index($(this));

     var startindex = previndex < currindex ? previndex : currindex;
     var stopindex = previndex > currindex ? previndex : currindex;

     $( tr ).slice(startindex, stopindex + 1).addClass( coloradd );
   }
   else
   {
     $(this).addClass( coloradd ); // this is 1st selected row
   }
}
问题回答

你们需要在两行之间找到兄弟,然后通过这两行走,来适用这一类别。

也许需要找到你点击哪一名儿童最初会把坐桌上的一些行数保留下来——然后发现你目前被点击的行数,然后你就可以在间行走。

当你选择第一行时,将适用特别安全等级。 然后,在轮班和选择另一行时,你只需要看上有<条码>栏目<<>。 CSS等级,在tr的表格收集中找到其位置或指数,只得上点击,把 j鱼的收集带回,然后加上。





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签