您好我只想用带按钮的文本字段中获取值。我有这个:
// Add extra contact clicked?
$('#add-contact p a').click(function(e) {
console.log('hallo');
var emailValue = $("input#contactpersonen-email").val();
console.log(emailValue);
// Make a copy of the first input fields
html = $('#new-contact').children().clone();
//$("#contactpersonen-email").val($("#contactpersonen-email1").val());
// 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;
});
所以我这样做:
var emailValue = $("input#contactpersonen-email").val();
console.log(emailValue);
这是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 required contactpersonen_email" id="contactpersonen_email" name="contactpersonen_email"></input>
</div>
</div>
但每次我都得到不确定的回复?那么如何获得价值呢?我不明白
谢谢
答案 0 :(得分:1)
看起来你有一个错字。这应该有效:
$(function() {
var emailValue = $("#contactpersonen_email").val();
console.log(emailValue);
});