我敢肯定这是一个简单的解决方法,但是经过研究我还没有弄清楚。
我有一个多页输入表单,该表单显示来自输入字段的数据摘要页面。输入字段具有描述该输入字段的默认字符串,基本上是'id'属性。当用户单击输入字段以输入数据时,默认数据消失,并输入新数据。如果用户未在输入字段中输入任何内容,则默认数据将保持应有的状态。摘要页面显示表单字段中的所有输入,包括默认数据。我遇到的问题是在显示摘要页面之前先弄清楚默认数据的清除方式。我敢肯定,这是我所忽略的简单事情,但是我需要另一组敏锐的眼睛和jquery敏锐的头脑。
摘要表格有两个表并排嵌入div中。我正在使用该nth-child()
方法选择正确td
的显示数据。
伪代码逻辑:“如果输入字段包含attr('id')
,则清除该字段;否则,显示该字段。”
我已经使用.val("")
,.val()
,.text("")
并.html("")
清除现场无济于事。我需要一些专业帮助。:-)
//prepare the fourth step
var fieldsLeft = new Array(
$('#firstname').val(),
$('#middlename').val(),
$('#lastname').val(),
$('#address').val(),
$('#city').val(),
$('#zip').val(),
$('#dob').val(),
$('#ssn').val()
)
var fieldsRight = new Array(
$('#homephone').val(),
$('#workphone').val(),
$('#cellphone').val(),
$('#employer').val(),
$('#emergency').val(),
$('#relationship').val(),
$('#phoneday').val(),
$('#phonenight').val(),
$('#email').val()
);
var sumLeft = $('#fourth_step #leftSummary tr');
sumLeft.each(function() {
var valueL = $(this).val();
if ( valueL == fieldsLeft[$(this).attr('id')]) {
$(this).children('td:nth-child(2)').val('');
} else {
$(this).children('td:nth-child(2)').html(fieldsLeft[$(this).index()])
}
});
var sumRight = $('#fourth_step #rightSummary tr');
sumRight.each(function() {
var valueR = $(this).val();
if ( valueR == fieldsRight[$(this).attr('id')]) {
$(this).children('td:nth-child(2)').val('');
} else {
$(this).children('td:nth-child(2)').html(fieldsRight[$(this).index()])
}
});
我让它使用占位符工作。如我所希望的那样,在为摘要视图提交表单时,输入字段中的默认文本消失了。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句