2011-07-19 13 views
2

msアクセスDataGrid内で同じイベントを複製しようとしていますが、矢印を上下に使用して行から移動できます。一例として、私は2行しか示していませんでしたが、はるかに多いかもしれません。jQuery // Arrow Downイベントで上下に移動

私は、だから私の質問は、私はjqueryのでarrow.downケース内に次のロジックを置くことができる方法で、次のHTML

<div class="cell celldata cell_service_data" id="cell_service_rate_1"> 
<input type="text" id="rate_service_row_1" class="rate_service_row"/> 
</div> 
<div class="cell celldata cell_service_data" id="cell_service_rate_2"> 
    <input type="text" id="rate_service_row_2" class="rate_service_row"/> 
</div> 

とjQuery

$('.rate_service_row').keydown(function (e) { 
    var rateId = $(this).attr('id'); 

    var keyCode = e.keyCode || e.which, 
     arrow = {left: 37, up: 38, right: 39, down: 40 }; 

    switch (keyCode) { 
    case arrow.left: 
     //.. 
    break; 
    case arrow.up: 
     //.. 
    break; 
    case arrow.right: 
     //.. 
    break; 
    case arrow.down: 
     //Set focus to the same cell next row 
    break; 
    } 
}); 

を持っています。
nextcell = cell_service_rate_1 + 1、私はあなただけのparseIntの(使用i = 1 ... nextcell = "cell_service_rate" + i;

EDIT のように行うことができない、正しく理解していれば)私はあなたが欲しいと思うものをやって、このjsfiddle作品をcell_service_rate_2

+0

4x4スクエアを投稿できますか?私は、階層がどのように構成されているかについてもう少し見たいと思います。 (さらに良い、グリッドのjsfiddle.netを作る) –

答えて

2

に等しくなければなりません。私はまだ文字列を作成するためにいくつかのカウンタを持っているよりエレガントだと思う。

http://jsfiddle.net/mazlix/byjmF/3/

EDIT

そしてHEREは、より多くの私はあなたがインデックス(この場合の '相対' 属性)

http://jsfiddle.net/mazlix/byjmF/9/

を持つことで、やるべきことだと思うものの一例です
+0

あなたが左と右を追加したいのであれば..ここに私がやったことですhttp://jsfiddle.net/mazlix/byjmF/10/ – mazlix

1

これと類似したものは?より良い

var rateId = $(this).attr('id'); 
//Get the number of the currently selected cell 
var curCell = rateId.substr(-1); 

... code ... 
case arrow.down: 
    //Go one row lower.. so plus 1 
    var newCell = curCell + 1; 
    //Define the new identifier 
    var newCellId = 'rate_service_row_' + newCell; 
    var element = $(newCellId); 
    //Focus on the element if it exists (element.length checks that) 
    if (element.length != 0) { 
      element.focus(); 
    } 
break; 

ではなく、これはちょうど0-9のために働くため、SUBSTR(-1)を行うよりも、あなたのrateIdのアンダースコアの最後の出現を検出することであろう。しかし、私はあなたがそのアイデアを得ると確信しています。

+0

グッドポイント0 -9。私は以下を追加します:var startAt = rateId.indexOf( "_"); var id = rateId.slice(startAt + 1、rateId.length) – Yannick

関連する問題