对于使用
JQuery-UI标签的页面,如何允许用户在标签标题中选择文本?
我有一些动态选项卡,并希望用户能够选择复制到剪贴板的标题.
例如在Demo page,我想要选择复制/粘贴’Nunc tincidunt’. “染色”和“艾琳”(Aenean lacinia).甚至是标题的一部分(例如“Proin”,“Aenean”,“tincidunt”).
解决方法
这是一个有点黑客的方法来替换定义选项卡的锚点,可选择< span>内容:
$(function() {
$( "#tabs" ).tabs();
$('.ui-tabs-anchor').each(function () {
var anchorText = $(this).text(),tabIndex = $(this).attr('id').split('-')[2] - 1;
$(this).hide();
$('<span class="selectable-tab-header">' + anchorText + '</span>').insertAfter(this).data('tabIndex',tabIndex);
});
$('.selectable-tab-header').click(function () {
$('#tabs').tabs('option','active',$(this).data('tabIndex'));
});
});