我有三个电子邮件文本框,其中包含三个不同的值。但它产生了相同的结果。我有这个:
$('.contactpersonen-email').each(function() {
var mails = $('.contactpersonen-email').map(function(){
return $(this).val();
}).get();
console.log(mails);
});
和HTML:
<div class="contact-label span2">
<label for="contactpersonen-email">Email adres</label>
<div class="contact-input-field">
<input type="text" class="input-text span2 contactpersonen-email" id="contactpersonen-email0" name="contactpersonen-email"></input>
</div>
</div>
这是整个剧本:
<![CDATA[
$(document).ready(function()
{
// Form validation
$(".klantregistratie form").validate({
rules: {
verploegen_form_klantregistratie_Bedrijfsnaam: "required",
verploegen_form_klantregistratie_Postcode: "required",
verploegen_form_klantregistratie_Plaats: "required",
verploegen_form_klantregistratie_Emailadres: {
required: true,
email: true
},
verploegen_form_klantregistratie_KvK_nummer: "required",
verploegen_form_klantregistratie_naam_eigenaar: "required",
verploegen_form_klantregistratie_Telefoon_mobiel: "required"
},
messages: {
verploegen_form_klantregistratie_Bedrijfsnaam: "De bedrijfsnaam is niet ingevuld",
verploegen_form_klantregistratie_Postcode: "De postcode is niet ingevuld",
verploegen_form_klantregistratie_Plaats: "De plaats is niet ingevuld",
verploegen_form_klantregistratie_Emailadres: {
required: "Je hebt geen email adres ingevuld",
email: "Je hebt geen geldig email adres ingevuld"
},
verploegen_form_klantregistratie_KvK_nummer: "Het KVK nummer is niet ingevuld",
verploegen_form_klantregistratie_naam_eigenaar: "De naam van de eigenaar is niet ingevuld",
verploegen_form_klantregistratie_Telefoon_mobiel: "Het (mobiele) telefoon nummer is niet ingevuld"
}
});
// Hide the textarea
$('#verploegen_form_klantregistratie_Contactpersonen').parent().parent().hide();
// Add extra contact clicked?
$('#add-contact p a').click(function()
{
// Make a copy of the first input fields
html = $('#new-contact').children().clone();
// Get number of tabs in the accordion
var index = $('#accordion h3').length;
// Remove the values
html.find("input[type=text]").val("");
html.find('input[type=checkbox]').attr('checked', false);
// New 'id', 'for' and 'name' attribute names
html.find('input[type=checkbox]').each(function () {
me = $(this);
attr = me.attr('id');
number = attr.split('_')[2];
newNumber = parseInt(index) + 1;
newAttr = attr.replace(number, newNumber);
me.attr('id', newAttr).attr('name', newAttr).next().attr('for', newAttr);
});
// Insert it at the end
$('#accordion').append(html);
$('#accordion').accordion('refresh');
// Set last tab to active
$("#accordion").accordion({ active: index });
// Cancel the click
return false;
});
// Submit clicked?
$('.submit-button input').click(function()
{
// Set variables
var html = '';
var i = 1;
// Loop through all the input fields for contacts
$('#accordion .user-row').each(function (uindex, uvalue) {
var mails = [];
$('.contactpersonen-email').each(function() {
mails.push($(this).val());
});
console.log(mails);
Array.prototype.areUnique = function() {
var l = this.length;
for(var i=0; i<l; i++) {
for(var j=i+1; j<l; j++) {
if (this[i] === this[j]) return false;
}
}
return true;
};
//if (!mails.areUnique()) {
// console.log ('values are not unique');
//} else {
// console.log('values are unique');
//}
html += '<tr>';
$(this).find('input').each(function (index, value) {
// Check if input type is a checkbox
if ($(this).is(":checkbox")) {
var JaNee = 'Nee';
if ($(this).is(":checked")) JaNee = 'Ja';
html = html + '<td>' + JaNee + '</td>';
}
else {
// Add the value into the html
html = html + '<td>' + $(this).val() + '</td>';
}
});
html += '</tr>';
});
// Set the value from the textarea to the generated html
$('#verploegen_form_klantregistratie_Contactpersonen').val('<table>'+html+'</table>');
});
});
$(function () {
$("#accordion").accordion({
heightStyle: "content"
});
});
]]>
谢谢你。 Als验证。和手风琴。 html是一样的。所以有一个电子邮件文本框
我现在就这样:
// Loop through all the input fields for contacts
$('#accordion .user-row').each(function (uindex, uvalue) {
var mails = $('.contactpersonen-email').map(function(){
return $(this).val();
}).get();
console.log(mails);
答案 0 :(得分:2)
您可能需要尝试以下操作:
var mails = [];
$('.contactpersonen-email').each(function() {
mails.push($(this).val());
});
console.log(mails);
答案 1 :(得分:0)
你不需要外UIViewContentModeScaleAspectFill
。 each
已经遍历所有元素,因此您实际上多次创建相同的数组
只需使用:
map()
&#13;
var mails = $('.contactpersonen-email').map(function(){
return $(this).val();
}).get();
console.log(mails);
&#13;