将多个值插入隐藏字段 [英] Insert multiple values into hidden field
本文介绍了将多个值插入隐藏字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个选择列表,您可以在其中选择多个城市-选择一个城市时,我想将邮政编码添加到隐藏字段中,现在我已将解决方案的值插入了隐藏字段,但是覆盖了该值如果是fx:点击一个新城市-它应该只附加到值上,例如:value ="value1 | value2 | value3"
I have a select list, where you can choose multiple cities - When choosing a city, i wanna add the Zipcode to a hidden field, the solution i have now inserts the value to the hidden field, however, it overwrites the value when fx: clicking a new city - It should just append to the value, like: value="value1|value2|value3"
$jq('.select-cities').click(function () {
var zipcodeValue = $jq(this).val();
//alert(zipcodeValue);
$jq('.hiddenFieldChosenAreas').val(zipcodeValue);
$jq('.select-cities option:selected').appendTo('.chosen-cities');
});
推荐答案
尝试一下:
$jq('.select-cities').click(function () {
var zipcodeValue = $jq(this).val();
//alert(zipcodeValue);
var oldVal = $jq('.hiddenFieldChosenAreas').val();
$jq('.hiddenFieldChosenAreas').val(oldVal+"|"+ zipcodeValue);
$jq('.select-cities option:selected').appendTo('.chosen-cities');
});
这篇关于将多个值插入隐藏字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文