开发者

how to implement focus() on selected text box with in gridview

i have a text box "txtSales" with in the gridview "gvClientView",how to do focus of selected row index in different function as a name is $("#close").click(function() .

 <script type="text/javascript">
 $(document).ready(function() {
     $("table[id*=gvClientView] input[type=text][id*=txtSales]").blur(function() {
         alert($(this.val());//here i am getting value of selected text box
     });

     $("#close").click(function(){ //h开发者_运维知识库ere i want to use focus of selected row of textbox in grid view });
 });
 </script>


I don't think the GridView expose any way to read the selected row in client side code, but if you say that in the .blur() you get proper textbox, just focus the last "blurred" textbox when clicking the button:

$(document).ready(function() {
    var lastBlurred = null;

    $("table[id*=gvClientView] input[type=text][id*=txtSales]").blur(function() {
        lastBlurred = this;
        alert($(this.val());//here i am getting value of selected text box
    });

    $("#close").click(function() {
        if (lastBlurred != null)
            lastBlurred.focus();
    });
});

Edit: to achieve what you want, you need to bind both blur() and focus() events:

$("table[id*=gvClientView] input[type=text][id*=txtSales]").bind("blur focus", function() {
        lastBlurred = this;
});

Quick test case shows the logic itself is working.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜