我从5选项卡表单中获取所有输入。通过它们循环时,我将它们添加到评论部分。我有它的工作正常,但我想显示选择下拉菜单的文本,而不是价值作为价值对用户没有意义。以下是我正在使用的几段代码。这是内部和$(:input.each(function(){}我检查它是否是一个选择。如果是这样我设置一个tmp变量并添加'_in'的名称,因为我有所有字段名称加上然后检查新变量的长度以确保它位于确认选项卡上,如果是,则将html更新为文本。问题是它显示所有下拉文本选项。如果我做.val( ),它给人的一个选择只值。从循环选择每个输入时获取文本
//Gives all text options from the drop down.
if ($(this).prop('type') == 'select-one') {
var tmp = '#'+$(this).attr('name')+'_in';
if ($(tmp).length > 0) {
$(tmp).html($(this).text());
}
}
//Gives only value of selected option from drop down.
if ($(this).prop('type') == 'select-one') {
var tmp = '#'+$(this).attr('name')+'_in';
if ($(tmp).length > 0) {
$(tmp).html($(this).val());
}
固定解
if ($(this).prop('type') == 'select-one') {
var tmp = '#'+$(this).attr('name')+'_in';
var tmp2 = '#'+$(this).attr('name')+' option:selected';
if ($(tmp).length > 0) {
tmp3 = $(tmp2).text();
$(tmp).html(tmp3);
}
}
检查两个代码块是否相同? – Adil 2012-07-18 15:22:24