如果里面有多个像这样的内容,你怎么从li获得这个类?
var ChooseAltType = $("<div>").appendTo(field_firstchild);
$('<div id="chooseCustomFields'
+ field_id
+ '" class="wrapper-customfields" tabindex="1"><span>Choose Type</span>'
+ '<ul id="chooseCustomField'
+ field_id
+ '" class="dropdown">'
+ '<li class="chooseCheckbox"><i class="fa-icon-check"></i>Checkbox</li>'
+ '<li class="chooseAlternatives"><i class="fa-icon-list-ul"></i> Alternatives</li>'
+ '<li class="chooseDropdown"><i class="fa-icon-list-alt"></i> Dropdown</li>'
+ '<li class="chooseTextField"><i class="fa-icon-font"></i> Text</li>'
+ '</ul></div>').appendTo(field_secondchild).addClass("metro three-d")
.click(function() {
alert($('#chooseCustomFields' + field_id + ' ul #chooseCustomField'
+ field_id + ' li').prevAll().length);
});
这只是一段代码,但我希望它已经足够了!
答案 0 :(得分:1)
这就是你能做的事情
var class= $("li").attr('class'); // you can use your own Selector instead of $("li")
答案 1 :(得分:0)
尝试
var ChooseAltType = $("<div>").appendTo(field_firstchild);
$('<div id="chooseCustomFields'
+ field_id
+ '" class="wrapper-customfields" tabindex="1"><span>Choose Type</span>'
+ '<ul id="chooseCustomField'
+ field_id
+ '" class="dropdown">'
+ '<li class="chooseCheckbox"><i class="fa-icon-check"></i>Checkbox</li>'
+ '<li class="chooseAlternatives"><i class="fa-icon-list-ul"></i> Alternatives</li>'
+ '<li class="chooseDropdown"><i class="fa-icon-list-alt"></i> Dropdown</li>'
+ '<li class="chooseTextField"><i class="fa-icon-font"></i> Text</li>'
+ '</ul></div>').appendTo(field_secondchild).addClass("metro three-d")
.click(function() {
$('#chooseCustomField' + field_id + ' li').each(function() {
console.log($(this).attr('classs'))
});
});