交换两个文本框值 [英] Swapping two text box values
本文介绍了交换两个文本框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个文本框值:-
var pickup = $('#txt-pickup');
var destination = $('#txt-destination');
,我想交换两个值,如下所示:-
and I want to swap the two values as follows:-
pickup.val(destination.val());
destination.val(pickup.val());
但是,以上将始终将两个值设置为相同的值. (与目标值相同)
However, the above will always set both values as the same value. (same as the destination value)
有没有办法同时更改这两者?
Is there a way of changing both of these at the same time?
推荐答案
我为您制作了一个jsfiddle:
I made a jsfiddle for you:
<input id="txt-pickup" type="text"/>
<input id="txt-destination" type="text"/>
<input id="change" type="button" value="Swap"/>
$(document).ready(function (){
$("#change").on('click',function(){
var pickup = $('#txt-pickup').val();
$('#txt-pickup').val($('#txt-destination').val());
$('#txt-destination').val(pickup);
});
});
这篇关于交换两个文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文