1

以下を含むColdFusion cfformがあります。

<cfinput type="text" name="part1" id="part1" tabIndex="1" onblur="enabled()" >
<cfinput type="text" name="part2" id="part2" tabIndex="2" onblur="enabled()" disabled="disabled" >
<cfinput type="text" name="part3" id="part3" tabIndex="3" onblur="enabled()" disabled="disabled" >

私が欲しいのは、前のボックスが空でない限り、入力ボックスを無効にすることです。

function enabled()
{
    var curIndex = + ( $( " * : focus " ).attr( " tabIndex " ) );
    var curVal = $( ' * : input [ tabIndex=' + curIndex + ' ] ' ).val();
    var nextIndex = curIndex + 1;
    var nextId = $( ' input [ tabIndex = " ' + nextIndex + ' " ] ' ).attr( " id " );
    if ( curVal == "" )
    {
        nextId.setAttribute( ' disabled ', ' disabled ' );
    }
    else
    {
        nextId.removeAttribute( ' disabled ' );
        nextId.focus();
    } 
} 

しかし、私はcurIndexを取得することに固執し、警告したときに「 undefined 」と表示されました。
どんな提案でも大歓迎です。

4

1 に答える 1

1

どうですか:

​$('input[type=text][name^=part]').on('blur',function(){​​​​​​​​​​​
    var el = $(this);
    var elNext = el.next('input[type=text][name^=part]');
    if(el.val()!=''){
        elNext.removeAttr('disabled');
    }else{
        elNext.attr('disabled',true);
    }
});

したがって、入力にハンドラーは必要ありません。

<cfinput type="text" name="part1" id="part1" tabIndex="1" > 
<cfinput type="text" name="part2" id="part2" tabIndex="2" disabled="disabled" > 
<cfinput type="text" name="part3" id="part3" tabIndex="3" disabled="disabled" >

<ahref = "http://jsfiddle.net/gionaf/wLnh7/"rel="nofollow">デモ

于 2012-10-10T10:06:10.760 に答える