开发者

How to show table in alt message

开发者 https://www.devze.com 2023-03-19 19:22 出处:网络
I am creating a page in asp.net. I am trying to show some information 开发者_如何学Goin tabular format when user hovers on a inout button. To do this, I am setting alt attribute to input type button b

I am creating a page in asp.net. I am trying to show some information 开发者_如何学Goin tabular format when user hovers on a inout button. To do this, I am setting alt attribute to input type button because it should be javascript independent. I tried creating a table and assigning it to the alt attribute as a text.

 <input type="button" value="save" alt="<table><tr><td>some info </td></tr>
 <tr><td>some other info </td></tr></table>"/>

But it is not displayed as a table with two ros. Instead it is displayed as a single line. Is there any way to show it in tabular format?


This is not possible just like this. Alt can be just plain text. You'll have to use JavaScript. Try to google for it :)

You'll have to: Create table. Using CSS, set it's position to absolute, near your control and display: none On item hover, you have to set display: block.

Best for this kind of behavior is to use some Javascript framework, IE jquery jquery.com

specially read these:

http://api.jquery.com/hover/

http://api.jquery.com/hide/

http://api.jquery.com/show/


Agreed with Ales, Javascript would make this a breeze. YUI's Tooltip allows you to instantiate a Tooltip associated with an element, or set of elements (changing the Tooltip's context, so in case you have many similar behaviours spread across a screen).

http://developer.yahoo.com/yui/examples/container/index.html

Once you have instantiated the Tooltip, its something like Tooltip.setBody("your HTML code");, though by default Tooltip sucks in title text of an <a> tag as its content, or possibly even alt text of an element - not 100% on the alt text default part though - good chance that if it doesn't do it by default, if you grab the alt attribute contents it will display it correctly inside the Tooltip.


Others have already told you that what you've asked for isn't possible, as HTML attributes must be plain text, not more HTML.

They've also told you that there are Javascript and JQuery libraries which will help you do what you're wanting to do. There are loads of scripts you could use, here's a link to one that you might want to try: http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/

However, I feel I should add one further point which others have missed, and which is actually quite important:

You're using the wrong attribute.

The alt attribute is not the correct attribute to use for a hover tooltip effect. You should be using the title attribute for this.

Using alt works this way for historic reasons in some browsers (I believe it works in IE, but not much else), but it is not intended as a tooltip. The correct use of alt is for a small bit of descriptive text that will appear if the image is not loaded. This could be because the file failed to load, or the user has images turned off, or the user has a text-to-speech browser, etc, but if the image is displayed, then this text should never be displayed.

The title attribute on the other hand is intended to be displayed, and all browsers implement it as a tooltip (in fact, it's not just on <img> tags; you can use title for any element).

Hope that helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消