我有以下脚本将输入值列表附加到textarea中。
<script>
function showValues() {
var fields = $(".content :input").serializeArray();
var tokens = jQuery.map(fields, function(field) {
return (field.value) ? (field.value + ' ' + field.name) : null;
});
$("#contentlist_copy").val(tokens.join(', '));
}
$("input").change(showValues);
showValues();
</script>
我想显示title属性,而不是显示返回字段的名称属性field.name
。我尝试了一些技巧,而不是给予。
我应该指出这是对此主题的后续问题:How to hide appended input names when the value is empty
答案 0 :(得分:0)
title属性未存储在serializeArray
中。您必须直接在.map
$(".content :input")
function showValues() {
var tokens = $(".content :input").map(function() {
return (this.value) ? (this.value + ' ' + this.title) : null;
}).get();
$("#contentlist_copy").val(tokens.join(', '));
}
$("input").change(showValues);
showValues();