我從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