如何将ID添加到动态创建的jQuery选项卡 [英] How to add the id to dynamically created jquery tab

查看:74
本文介绍了如何将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.

这篇关于如何将ID添加到动态创建的jQuery选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆