【发布时间】:2012-01-30 04:41:03
【问题描述】:
我刚刚遇到了一个问题,我将选择转换为<ul><li/></ul> 格式。
现在我将所有选项、它们的值、html 和类都转换为 li。
这意味着 li 获取值属性等。
手头的问题 It works perfectly fine when the options have integers (currently below 4 digits) and convert them.但我有另一个选择选项有 guid 作为值。当我尝试转换时,所有值都为零,即 value="0"。
有人有什么想法吗?
我的代码完全正确:
//Extract listbox
$preferenceListBox.children().each(function () {
var $liToAdd = $liTemplate.clone();
console.log($(this).val());
$liToAdd.html($(this).html()).prop("value",$(this).val()).prop("disabled", $(this).prop("disabled"));
if ($(this).is("[disabled='disabled']") || $(this).is("[selected='selected']")) {
$liToAdd.addClass("disabled");
}
if ($(this).filter(":selected") > 0) {
$liToAdd.prop("disabled", "disabled");
}
$selectionList.append($liToAdd);
});
更新
转换后的列表 html 示例:
<ul class="selectionList"><li value="0" class="ui-draggable ui-selectable">-Select-<b class="preferenceButton">+</b></li><li value="0" class="ui-draggable ui-selectable">Canberra Central<b class="preferenceButton">+</b></li>...</ul>
它是从这个选择中创建的:
<select class="preferenceListBox noSelectItem" id="areaCodeList" multiple="multiple" name="areaCodeList" size="7" style="display: none; "><option disabled="disabled" class="disabled">-Select-</option><option value="24631a28-901d-4156-b6f6-2d2b3c10c9ec">Canberra Central</option>...</select>
【问题讨论】:
-
任何 html 代码示例,或者可能是示例 GUID?
-
我刚刚为你添加了示例
-
阅读我的答案,你不能在 li 标签的 value 属性中使用字母
标签: javascript jquery