添加选项以选择菜单开头的菜单 [英] add option to select menu at the beginning of the menu
本文介绍了添加选项以选择菜单开头的菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在选择菜单的开头为菜单添加选项?
How can I add an option to a menu at the begining of the select menu?
我知道追加将添加结尾
SomeSelectMenu.append(NewElement);
但我如何在开头添加?
以下是一个示例:
But how will I add at the beginning? Here is an example:
<select>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
请用Jquery指定答案,不指定答案(如果可能)
谢谢
Please specify an answer with Jquery and one without (if possible) Thanks
推荐答案
你真是太近了! :)
.prepend( content, [content] )
$('select').prepend('<option value="i-came-first">Hey!</option>');
http://api.jquery.com/prepend/
这篇关于添加选项以选择菜单开头的菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文