1

我正在使用 Telerik Radeditor,它是富文本区域,编辑器内容是 iframe,如下所示:

 <iframe frameborder="0" 
    src="javascript:'<html></html>';" 
    style="width: 100%; height: 100%; margin: 0px; padding: 0px;" 
    title="hello world" 
    id="contentIframe"></iframe>

我的目标是"hello world"在用户鼠标悬停在 iframe 区域时显示工具提示。

正如你所看到的,我放了"title" attribute但它没有出现。

为了模仿工具提示行为,我尝试放置overlay div并且title有效,但后来我失去了鼠标控制,因为overlay div.

我还拼命尝试将标题放在 iframe 正文中,但随后我不得不单击 iframe 内部以使其发生,这不是解决方案。

var iframe_html = $(wrapper).find("iframe").contents().find("html");
$(iframe_html).prop("title", "hello my tooltip 1");
var iframe = $(wrapper).find('iframe');
$(iframe).prop("title", "hello my tooltip 2");
var iframebody = $(iframe).contents().find('body');
$(iframebody).prop("title", "hello my tooltip 3");

我正在使用jQuery UI 1.8.16它不附带工具提示功能,因此这不是一个选项..

谁能帮我弄清楚如何显示工具提示?

4

2 回答 2

1

您可以为 iframe 分配一个标题,但您将无法在 iframe 中看到它。将 frameborder 更改为“2”并将光标移动到它.. 你去......标题出现......

要查看 iframe 上的标题,您必须设置 iframe 内容的标题,而不是 iframe 本身。

就像我在下面所做的一样..

<iframe frameborder="0" 
    src="javascript:'<div id=\'hey\' title=\'Hello World\'>Helllo World</div>';" 
    style="width: 100%; height: 100%; margin: 0px; padding: 0px;position:relative;" 
    title="hello world" 
    id="contentIframe">
</iframe>

或者.. 使用 jQuery

$(document).ready(function () {    
    $("#contentIframe").contents().find("body").attr('title','Hello World');    
});

这是一个供您参考的小提琴..

于 2013-04-15T17:53:39.133 回答
0

我刚刚在 w3 学校工具提示教程(此处为 TryIt 编辑器)中向 div 添加了一个 iframe,它运行良好。出乎我的意料。

<!DOCTYPE html>
<html>
<style>
.tooltip {
    position: relative;
    display: inline-block;
    border-bottom: 1px dotted black;
}

.tooltip .tooltiptext {
    visibility: hidden;
    width: 120px;
    background-color: #994444;
    color: #ffffff;
    text-align: center;
    border-radius: 6px;
    padding: 5px 0;

    /* Position the tooltip */
    position: absolute;
    z-index: 1;
    bottom: 100%;
    left: 50%;
    margin-left: -60px;
}

.tooltip:hover .tooltiptext {
    visibility: visible;
}
</style>
<body style="text-align:center;">

<h2>Proof of Concept</h2>
<p>This, cobbled from the W3 schools tutorial on CSS tooltips.  I added an Iframe inside the div; one may still interact therewith, yet enjoy full tooltipitude.</p>
<p> So, move the mouse over the text below:</p>

<div class="tooltip">Hover over me
  <span class="tooltiptext">Hello World</span>
  <iframe height="600px" src="https://imgur.com/a/71J1gQZ" width="600px" ></iframe>
</div>

</body>
</html>

在这里看到它:

https://faustsstudy.blogspot.com/p/blog-page_14.html

但它需要对数据 URI 的支持。

于 2018-11-14T22:54:57.660 回答