我正在动态创建选项卡。我创建了一个按钮removeTabs来删除选项卡。它工作正常,但是当我尝试使用 div * x * 时它不起作用..
html
<!DOCTYPE html>
<html>
<head>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script>
$(document).ready(function() {
$("#tabs").tabs();
});
</script>
</head>
<body style="font-size:62.5%;">
<div id="tabs">
<ul>
</ul>
</div>
<input type='button' id='addTab' value='Add Tab'>
<input type='button' id='removeTab' value='RemoveTab'>
</body>
</html>
JS:
$(function() {
var index = 0;
index++;
$("#addTab").live ('click',function() {
index++;
var title = 'Tab..... ' + index + ' <p title="close" id="removeTab" style="cursor: pointer; display: inline" >x</p>';
var url = '#fragment-'+index;
addTab(url,title,index);
});
function addTab(url, title, index) {
$('#tabs').tabs("add",url,title,[index]);
}
$('#removeTab').live('click',function() {
var $tabs = $('#tabs').tabs();
var selected = $tabs.tabs('option', 'selected');
alert(selected);
$('#tabs').tabs("remove" , [selected] );
});
});
当我点击x时它不起作用
JS 小提琴:http: //jsfiddle.net/6VrwD/23/