我尝试从输入字段向表单添加选择选项。我在所有浏览器中都能正常工作,除了IE似乎没有添加选项。感谢帮助!
HTML
<select name="folder" id="folder" class="select Slectbox">
</select>
<label for="addfolder">Add Folder</label>
<input type="text" class="input-add-list" placeholder="new folder name" />
<button onClick="return false;" class="spr btn">Add</button>
JQUERY
<script>
$('.spr').on('click',function(){
if($('.input-add-list').val().trim()!=='')
{
$('.SlectBox').append('<option value="'+$('.input-add-list').val().trim()+'">'+$('.input-add-list').val().trim()+'</option>');
$("select option:last").attr("selected","selected");
}
});
</script>