如何在HTML选择列表中显示多个空格< option>< / option> [英] How to display multiple spaces in HTML select list <option></option>

查看:844
本文介绍了如何在HTML选择列表中显示多个空格< option>< / option>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jsfidder here ):

 < select id = 列表 > 
< option>一个空格< / option>
< option> two  spaces< / option>
< option> three & nbsp; spaces< / option>
< / select>

更新小提琴


jsfidder here http://jsfiddle.net/a3LwW/4/

My problem is I have multiple spaces in the content of <option>

jQuery val() gives me correct value, but browser renders the <option> as if there is only a single space in the string.

Is there a way to to render multiple spaces correctly in <option>??

I tried <option><pre>three spaces</pre></option>, but it doesn't do what I want.

HTML

<select id="list">
    <option>one space</option>
    <option>two  spaces</option>
    <option>three   spaces</option>
</select>
<p>Current Value:<pre id="val"></pre></p>

JS

function update_val () {
    $('#val').text($('#list').val()); 
}

$('#list').change(update_val);

//init
update_val();

解决方案

Use &nbsp; (normally you shouldn't use this for spacing, but you don't have many more options in <select> elements):

<select id="list">
    <option>one space</option>
    <option>two &nbsp;spaces</option>
    <option>three &nbsp;&nbsp;spaces</option>
</select>

Updated Fiddle

这篇关于如何在HTML选择列表中显示多个空格&lt; option&gt;&lt; / option&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆