如何在HTML中保留空间选择选项列表< option value ='hi this'> hi</option> [英] how to preserve space in HTML select option list<option value='hi this'>hi</option>
问题描述
我有一个选择控件.我尝试用jquery更新此控件,但省略空格后的值.
I have one select control. I try to update this control with jquery but the value after space omitting.
if (brandObj != "") {
brandObj = eval("(" + brandObj + ")");
$.each(brandObj, function(i, item) {
$("#<%=listBrand.ClientID%>").append( "<option value="+ item.Brand + ">" + item.Brand + "</option>");
});
}
我从服务器获取的数据
但是在将其渲染为HTML select之后,它省略了空格之后的单词.整个值在那里,但是一旦我获得了值,它只有一半(双引号中的值).我尝试添加
,但它按原样显示.它不是渲染为空间.请提出您的建议.
But after it render as HTML select , it omit the word after space.whole value is there but once I get the value , it have only half(the value which in double quote). I tried to add
but it is showing as it is. it is not rendering as space. please give your suggession.
推荐答案
您应该将属性值的值包装在quote(Quote It)中.如果不将其用引号引起来,则空格后的值将被视为属性本身:
You should wrap value of attribute value in quote(Quote It). If you do not wrap them in quote then value after space will be considered as attribute itself:
$("#<%=listBrand.ClientID%>").append("<option value='"+ item.Brand + "'>" + item.Brand + "</option>");
这篇关于如何在HTML中保留空间选择选项列表< option value ='hi this'> hi</option>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!