如何将ID添加到动态创建的jQuery选项卡

问题描述:

我正在动态创建jQuery选项卡.我想将ID分配给每个标签.

I am creating dynamically jQuery tabs. I want to assign the id to each tab.

$("#addTab").live('click', function() {
    index++;
    var title = 'Tab.....  ' + index;
    var url = '#fragment-' + index;

    addTab(url, title, index);
    $('li[class=ui-state-default]').id(this)=1; // this line to add id

});

但ID未分配给该标签.

but id is not assigning to the tab..

JS小提琴

$('li.ui-state-default:last').attr('id', 'some_' + index); // only Numeric id not allowed

演示

DEMO

注意::$('li.ui-state-default').attr('id', 'some_' + index);已更改所有li的ID为类ui-state-default,但当前代码只会更改最后一个id.

NOTE: $('li.ui-state-default').attr('id', 'some_' + index); was change all li's id have class ui-state-default, but current code will only change the last one's id.