在我看来和你的代码实验中,可能无法直接(
failed code).但是如果你想要解决它/修复它,你可以使用像purecss这样的小型外部库(取其菜单组件)并简单地编写如下代码:
只是一个提出想法的例子.
HTML:
jQuery的:
$(".pure-menu-children li").each(function(i, opt){
var colors = $(opt).find(".pure-menu-link").attr("value"); // get the value
var txt = $(opt).find(".pure-menu-link").text(); // get the text
var txtarr = txt.trim().split(" "); // split them
var colorarr = colors.trim().split(" ");
$(opt).find(".pure-menu-link").html(""); // clear the content of the option
var len;
if(txtarr.length >= colorarr.length){
len = txtarr.length - colorarr.length;
while(len--){
colorarr.push("black");
}
}
len = txtarr.length;
while(len--){
$(opt).find(".pure-menu-link").append(" "+txtarr.shift()+" ");
}
});
希望能帮助到你.