我已经动态创建了 jquery 选项卡。我想重命名选项卡。当我单击选定的选项卡时。一个文本框出现在模糊上,它将文本框的值设置为选项卡。再次,当我尝试对另一个选项卡执行此操作时,它会重命名当前和早期选项卡。等等...
$(document).ready(function() {
$("#tabs").tabs({
tabTemplate: "<li><a href='#{href}'>#{label}</a> <p title='close' id='removeTab' style='cursor:pointer;display:inline'>x</p></li>"
});
});
$(function() {
for (i=0; i<3; i++){
var title = '<span id="a'+i+'">Tab..... ' + i;
var url = '#fragment-' + i;
addTab(url, title, i);
}
var index =10;
index++;
$("#addTab").live('click', function() {
index++;
var title = '<span id="a'+index+'">Tab..... ' + index;
var url = '#fragment-' + index;
addTab(url, title, index);
});
function addTab(url, title, index) {
$('#tabs').tabs("add", url, title, [index]);
$('#a'+index).click(function(){
var _current = '#a'+index
if($(_current ).parent().parent().hasClass('ui-tabs-selected')){
$(_current).hide();
$('#editTabName').stop(false, true).hide();
var nameField = '#editTabName';
$(nameField).css({
top: '12px',
left: $(this).parent().offset().left + 8+'px',
zIndex:100,
position:'absolute'
});
$(nameField).val($(_current).html());
$(nameField).show(50);
$(nameField).focus();
$(nameField).blur(function (){
alert(_current);
newName = $(nameField).val();
$(_current).html(newName);
$(nameField).hide();
$(_current).show();
});
}
});
}
$('#removeTab').live('click', function() {
var $tabs = $('#tabs').tabs();
var selected = $tabs.tabs('option', 'selected');
if(selected == -1)
selected = $('p[id=removeTab]').index(this);
$('#tabs').tabs("remove", [selected]);
});
});