使用jQuery,我将select复制到ul中以便在移动应用程序中使用.select选项中的某些值具有前导0.我在li元素中使用自定义属性来模仿select选项中的值.
当我将值复制到li:值时,它会失去前导0.我甚至尝试将整个li创建为我附加到外部ul的升字符串.
html:
<select id="seltest">
<option value="011111">good bye</option>
</select>
<div id="container"></div>
javascript:
$("#container").append("<ul id='thefilter'></ul>");
$("#seltest option").each(function () {
var optval = $(this).val();
var strvar = '<li value=\"' + String(optval) + '\">' + $(this).text() + '</li>';
alert(strvar);
$("#thefilter").append(strvar);
var lastli = $("#thefilter li:last");
alert(lastli[0].outerHTML); // now the value has lost the leading 0
});
Run Code Online (Sandbox Code Playgroud)
这是一个展示示例的小提琴:http://jsfiddle.net/richbuff/4RbH9/7/
有没有人知道如何保持领先的0?似乎jQuery正在修改我的文本.
TIA!
浏览器实际上是在执行规范.来自Mozilla开发者网络:
The only allowed value for this attribute is a number, even if the list is displayed with Roman numerals or letters.
在我少数几年的Web开发中,我从未value在列表项上使用该属性.所以,你们中的一些人可能会发现这个额外的兴趣:
This attribute was deprecated in HTML4, but reintroduced in HTML5.