渲染HTML字符串的工具提示 [英] Render Html String in tooltip

查看:109
本文介绍了渲染HTML字符串的工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个asp.net日历。在日历的DayRender事件我想渲染HTML作为提示。

I have a asp.net Calendar. On DayRender event of calendar I want to render html as tooltip.

e.Cell.ToolTip= HttpUtility.HtmlEncode("add<BR>peek") 

但它不工作。如何在浏览器中呈现为html.But它被渲染为

But its not working. How to render in browser as html.But it was rendering as

"asdsa&lt;BR&gt;peek"

编辑:
我试着像这样以另一种方式。

I tried like this in another way.

Label b = new Label();
b.Visible = false;
b.Text = "add<BR>peek";
e.Cell.Controls.Add(b); 

显示的罚款。但我想onhover日历日期显示的标签。我怎样才能做到这一点?任何一个可以帮助我。
先谢谢了。

Displaying fine. But I want to display label onhover the calendar date. How can I do this? Can any one help me. Thanks in Advance.

推荐答案

实现,这将是与jQuery的最简单方法。您需要使用CSS类,使含有细胞和标签识别到不显眼的JavaScript。然后,您可以创建当小区盘旋了一个功能上它会发现标签并显示它,然后隐藏,当鼠标移开:

The easiest way to achieve this would be with jQuery. You need to make the containing cell and the label identifiable to unobtrusive javascript by using css classes. Then you can create a function for when the cell is hovered over which will find the label and display it, then hide when the mouse moves away:

追加以下几行你已经在服务器端逻辑:

Append the following lines to the server side logic you have already:

b.CssClass = "js-tooltip";
e.Cell.CssClass = "js-tooltip-container";

您应该HTML然后像(你不必code这部分,其背后的的code的结果):

Your html should then look like (you don't have to code this part, its the result of your code behind):

<td class="js-tooltip-container">
    <label class="js-tooltip" style="display:none;">add <br /> peek</label>
</td>

然后你需要添加下面的jQuery的:

Then you need to add the following jQuery:

<script type="text/javascript">
$(function(){
    $(".js-tooltip-container").hover(function(){
        $(this).find(".js-tooltip").show();
    }, function(){
        $(this).find(".js-tooltip").hide();
    });
});
</script>

JavaScript的使用了 jQuery的悬停功能的。这是所有的锅炉板的东西,所以,如果你想要的东西更强大的和可定制的我会考虑使用该插件的一个建议这里

The javascript makes use of the jQuery hover function. This is all boiler plate stuff so if you want something more robust and customisable I would consider using one of the plugins suggested here.

这篇关于渲染HTML字符串的工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆