是否可以使用Tabs而不使用锚标记和ID?
我想生成动态标签。 所以锚标签不会有id也div标签不会有id。
这是我尝试做但它不起作用。
$(function () { $("#tabs").tabs(); $("#tabs ul.super li a").each(function (index) { $(this).click(function () { $("#tabs").tabs("select", index); }); }); });
我怎么能让它像那样工作?
使用上面的Nuri Yilmaz代码,这里是一个jquery插件,使标签完全不使用id:
/** * use: * * * * - Tab label
* ... some more tab lables *
* some content * ... some more div.tab_el * * * */ (function( $ ){ $.fn.noIdTab = function() { this.each(function(){ var rand = 'spec' + (new Date()).getTime() + Math.floor((Math.random()*25)+65); $(this).find('ul.super li a').each(function (index) { $(this).attr("href", "#" + rand + index.toString()); }); $(this).find('div.tab_el').each(function (index) { $(this).attr("id", rand + index.toString()); }); $(this).tabs(); }); }; })( jQuery );