我想结合多个输入,然后将它们组合起来形成一个句子/短语。这个例子将更详细地阐述它。结合不同输入的数组
INPUT1:快乐
INPUT2:您生日快乐
INPUT4:你属于动物园
输入5:与猴子和驴
输入6:大猩猩是你
输出:
快乐,您生日快乐,你属于动物园,与猴子和驴,大猩猩是你
预期输出:
快乐Birthda y对你来说,你属于动物园,猴子和驴子,大猩猩就是你
我想设置一个条件,在INPUT中不会用逗号(,)连接而只是一个空格。我怎样才能做到这一点?这是一个小提琴和代码。感谢所有帮助日Thnx
小提琴:http://jsfiddle.net/hztMj/6/
代码:
<input class="combine" id="input1" disabled="true" value="Happy"></input>
<input class="combine" id="input2" disabled="true" value="Birthday to you"></input>
<input class="combine" id="input3" disabled="true" value="You belong to the zoo"></input>
<input class="combine" id="input4" disabled="true" value="and the monkey and the donkey"></input>
<input class="combine" id="input5" disabled="true" value="The Gorilla is you"></input>
<input class="combine" id="Voltes5" disabled="true" size="75"></input>
<button id="LaserSword">Set</button>
JS
$(document).ready(function() {
$('#LaserSword').on('click', function() {
var form = $('.combine').not('#Voltes5');
var val = form.map(function() {
var value = $.trim(this.value)
return value ? value : undefined;
}).get();
$('#Voltes5').val(val.join(', '))//part to be improved
});
});