年/月/日输入

时间:2013-03-05 17:23:54

标签: focus

我正在寻找一些简单的代码

< input type =“text”name =“year”maxlength =“4”>

< input type =“text”name =“month”maxlength =“2”>

< input type =“text”name =“day”maxlength =“2”>

因此,当我完成键入年份时,它将关注月份然后停止。

我似乎无法在Google中找到合适的搜索词。我确信这已由1000人完成。

1 个答案:

答案 0 :(得分:0)

试试这段代码;我用jQuery来完成这个。您需要在同一目录中包含jquery,并为每个输入添加“id”属性。

<script src='jquery.js' type="text/javascript"></script>

<input type="text" name="year" id="year" maxlength="4">

<input type="text" name="month" id="month" maxlength="2">

<input type="text" name="day" id="day" maxlength="2">

<script type="text/javascript">
    $("#year").bind( 'keypress', function(e) {
        if( $("#year").val().length >= 4 ) 
            $("#month").focus();
    });
    $("#month").bind( 'keypress', function(e) {
        if( $("#month").val().length >= 2 ) 
            $("#day").focus();
    });
</script>
相关问题