jQuery-将值从一个输入传递到另一个 [英] jQuery - passing value from one input to another

查看:98
本文介绍了jQuery-将值从一个输入传递到另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,其中有几个输入字段,分别是titlenameaddress

I have a form, with several input fields that are title, name, address etc

我要做的是获取这些值并将其放入"其他输入字段的值中.例如

What I want to do, is to get these values and 'put them' into values of other input fields. For example

<label for="first_name">First Name</label>
<input type="text" name="name" />

<label for="surname">Surname</label>
<input type="text" name="surname" />

<label for="firstname">Firstname</label>
<input type="text" name="firstname" disabled="disabled" />

因此,如果我在first_name字段中输入John,那么firstname的值也将是John.

So If I enter John in the first_name field, then the value of firstname will also be John.

非常感谢

推荐答案

假设您可以在输入中添加ID:

Assuming you can put ID's on the inputs:

$('#name').change(function() {
    $('#firstname').val($(this).val());
});

JSFiddle示例

否则,您必须使用以下名称进行选择:

Otherwise you'll have to select using the names:

$('input[name="name"]').change(function() {
    $('input[name="firstname"]').val($(this).val());
});

这篇关于jQuery-将值从一个输入传递到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆