我有一个选项列表,我想做的是将所选选项的文本替换为当前选项的值。
<select name="sorting-box" class="sort-box" id="sort">
<option value="Alphabetical">Alphabetical</option>
<option value="Math: ↑ to ↓">Math Required: High to Low</option>
<option value="Math: ↓ to ↑">Math Required: Low to High</option>
<option value="Lang: ↑ to ↓">Second Language Required: High to Low</option>
<option value="Lang: ↓ to ↑">Second Language Required: Low to High</option>
<option value="Salary: ↑ to ↓">Average Starting Salary: High to Low</option>
<option value="Salary: ↓ to ↑">Average Starting Salary: Low to High</option>
<option value="Credits: ↑ to ↓">Credits Required: High to Low</option>
<option value="Credits: ↓ to ↑">Credits Required: Low to High</option>
</select>
$('#sort').change(function(){
$(this).find('option:selected').text($(this).find('option:selected').attr('value'));
});
它与此类似,但如果未选择它,我无法确定如何让它切换回来,所以它保持原样。
我在想也许可以添加一个类,并在类上检测?任何的意见都将会有帮助。