如果我有<span>some text</span>
,我怎样才能拥有这个:
<span title="*whatever is between span tags:* some text (in this case)">some text</span>
最佳答案
如果您自己构建 HTML,则只需在生成 html 时将文本添加到标题属性中即可。例如,在 PHP 中它将是:
$text = 'some text';
<span title="<?php echo htmlspecialchars($text) ?>"><?php echo $text ?></span>
如果您事后通过 Javascript 执行此操作,则(使用 jquery):
$('span').each(function () {
this.attr('title', this.text());
});
关于javascript - 添加tooltip,其值与span值相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6932200/