简体   繁体   English

将多个输入值克隆到一个输入字段中

[英]Clone multiple input values into one input field

I'm trying to copy the input data of multiple fields into one big one, for date of birth. 我试图将多个字段的输入数据复制到一个大字段中,以便出生日期。

day value + month value + year value = day value/month value/year value into one other field all together. 日值+月值+年值=日值/月值/年值一起进入另一个字段。 I made variables of each field and then try to add them in the 'full' input field, but this doesn't work. 我创建了每个字段的变量,然后尝试将它们添加到“完整”输入字段中,但这不起作用。 What am I doing wrong? 我究竟做错了什么?

Demo: http://jsfiddle.net/J2PHq/ 演示: http//jsfiddle.net/J2PHq/

$(function(){
    $('.copy').on('keyup blur', function(){
         $('.full').val(day + '/' + week + '/' + year);

        day = $(".day").val();
        week = $(".week").val();
        year = $(".year").val();
     }).blur();
});

Wrong execution order - 执行顺序错误 -

$(function(){
    $('.copy').on('keyup blur', function(){
        var day = $(".day").val();
        var week = $(".week").val();
        var year = $(".year").val();
        $('.full').val(day + '/' + week + '/' + year);
     }).blur();
});

Demo ---> http://jsfiddle.net/J2PHq/6/ 演示---> http://jsfiddle.net/J2PHq/6/

You need to declare the variables before you enter them in the .full field. .full字段中输入变量之前,需要声明变量。

Working fiddle: here 工作小提琴: 这里

$(function(){
    $('.copy').on('keyup blur', function(){        
        var day = $(".day").val();
        var week = $(".week").val();
        var year = $(".year").val(); 

        $('.full').val(day + '.' + week + '.' + year);

     }).blur();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM