本文介绍了< select>中的字体预览下拉列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我一直在寻找,而在下拉列表中,如何使字体预览(在同一个字体中显示文本)真的没有太多。有人可以指出我正确的方向吗?谢谢。解决方案提供仅使用的选项 a select 元素,那么将允许使用字体样式,并应用其他CSS,同时更新传统的选择元素以提交给服务器/脚本: html: < form action =#method =post> < select id =fontSelectorname =fontSelector> < option value =calibri> Calibri< / option> < option value =Times New Roman> Times New Roman< / option> < option value =Comic Sans MS> Comic Sans MS< / option> < / select> < / form> < ul id =fontList> < li id =calibriclass =selected> Calibri< / li> < li id =timesNewRoman> Times New Roman< / li> < li id =comicSansMS> Comic Sans MS< / li> < / ul> jQuery: code $ $('#fontList li')。click( function(){ var selected = $(this).index(); $('#fontSelector option :select') .removeAttr('selected'); $('#fontSelector选项') .eq(selected) .attr('selected',true) ; $('。selected')。removeClass('selected'); $(this).addClass('selected'); }); JS小提琴演示。 注意: li 元素的顺序将与选项元素的顺序相同,因为选择选择由索引( li )选择。 li> 参考文献: click() 。 index() 。 removeAttr() 。 eq() 。 attr() 。 removeClass() 。 addClass() 。 I've been looking around and there's really not much on how to make font previews (to show the text in the same font they're selecting) in a dropdown list. Can anybody point me in the right direction? Thanks. 解决方案 To offer an alternative to using only a select element, that will allow for styling the font, and applying other css, while updating a traditional select element for submission to the server/script:html:<form action="#" method="post"> <select id="fontSelector" name="fontSelector"> <option value="calibri">Calibri</option> <option value="Times New Roman">Times New Roman</option> <option value="Comic Sans MS">Comic Sans MS</option> </select></form><ul id="fontList"> <li id="calibri" class="selected">Calibri</li> <li id="timesNewRoman">Times New Roman</li> <li id="comicSansMS">Comic Sans MS</li></ul>jQuery:$('#fontList li').click( function(){ var chosen = $(this).index(); $('#fontSelector option:selected') .removeAttr('selected'); $('#fontSelector option') .eq(chosen) .attr('selected',true); $('.selected').removeClass('selected'); $(this).addClass('selected'); });JS Fiddle demo.Notes:This assumes that that the order of the li elements will be the same as the order of the option elements, since the option that becomes selected is chosen by index (of the li).References:click().index().removeAttr().eq().attr().removeClass().addClass(). 这篇关于< select>中的字体预览下拉列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-31 03:54