开发者

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

开发者 https://www.devze.com 2023-03-23 21:37 出处:网络
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() .

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

精彩评论

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