最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jquery set tabindex and cursor - Stack Overflow

programmeradmin4浏览0评论

I have the following code that assigns tabindex to my form id "register1". I would like to place the cursor on the first input or select list item on the form (item with tabindex = 1) once tabindexes are assigned. but the following line: $('#register1').find('input').attr('tabindex',1).select(); Resets tabindex of all the inputs.

Full code:

$(function(){
    var tabindex = 1;
    $('#register1').find('input,select').each(function() {
        if (this.type != "hidden") {
            var $input = $(this);
            $input.attr("tabindex", tabindex);
            tabindex++;
        }
    });
    $('#register1').find('input').attr('tabindex',1).select();
});

thanks

I have the following code that assigns tabindex to my form id "register1". I would like to place the cursor on the first input or select list item on the form (item with tabindex = 1) once tabindexes are assigned. but the following line: $('#register1').find('input').attr('tabindex',1).select(); Resets tabindex of all the inputs.

Full code:

$(function(){
    var tabindex = 1;
    $('#register1').find('input,select').each(function() {
        if (this.type != "hidden") {
            var $input = $(this);
            $input.attr("tabindex", tabindex);
            tabindex++;
        }
    });
    $('#register1').find('input').attr('tabindex',1).select();
});

thanks

Share Improve this question asked Jul 22, 2011 at 5:46 ShaneKmShaneKm 21.3k46 gold badges175 silver badges307 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

Try :

$('#register1').find('input[tabindex=1]').whatyouwant()

Simply select the item with tabindex one in your loop using a condition:

$(function(){
    var tabindex = 1;
    $('#register1').find('input,select').each(function() {
        if (this.type != "hidden") {
            var $input = $(this);
            $input.attr("tabindex", tabindex);

            // select the first one.
            if (tabindex == 1) {
               $input.select();
            }
            tabindex++;
        }
    });
});
发布评论

评论列表(0)

  1. 暂无评论