如何隐藏数据? [英] How do I hide the data ?

查看:128
本文介绍了如何隐藏数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个'div'标签。为此,我绑定了一些数据,例如每个人都有帮助,因为他们喜欢帮助。



现在我必须展示比如这里的每个人...... 。在我的html网格中(以'Div'标签绑定)



我们可以通过调整'div'宽度来实现吗?需要一些建议...



提前谢谢,

I have a 'div' tag.For this i am binding some data like "Everyone here helps because they enjoy helping".

Now i have to show like "Everyone here...." in my html Grid(Bound in 'Div' tags)

Can we do it by adjusting the 'div' width? need some suggestions...

Thanks in advance,

推荐答案

调整元素大小将是一个馊主意。首先,您将无法正确估计Javascript中某些文本的大小。即使您拥有字体度量和文本内容的完整信息以及编程和原始操作系统API(您在Javascript中无法访问)的全部功能,由于字体提示和其他复杂性,这是一个众所周知的难题。而且,毕竟,一些代码需要添加...(顺便说一下,& hellip; ,而不是三个点)。



你真的需要保留元素自我调整大小,具体取决于内容,并动态更改内容以显示少量的第一个单词和& hellip; 。你可以用Javascript做到这一点。为此,您需要计算文本的缩短版本并记住代码中的这些值(这与Javascript数组有关,Javascript数组用作关联容器,搜索的O(1)复杂度)。然后,您需要处理悬停事件(例如,根据您的设计,它可能是其他东西)来显示完整或缩短的文本。 div 的大小将根据其内部HTML和CSS(填充)自动调整。



To处理此类事件,最好使用jQuery,例如: http://api.jquery.com/hover [ ^ ]。



缩短文本的计算可以使用函数 split()

http://www.w3schools.com/jsref/jsref_split.asp [ ^ ]。



如果您需要学习jQuery(强烈推荐),请参阅:

http://en.wikipedia.org/wiki/JQuery [ ^ ],

HTTP:// jquer y.com [ ^ ],

< a href =http://learn.jquery.com/> http://learn.jquery.com [ ^ ],

http:// learn.jquery.com/using-jquery-core [ ^ ],

http://learn.jquery。 com / about-jquery / how-jquery-works [ ^ ](从这里开始)。



-SA
Adjusting the element size would be a bad idea. First, you won't be able to correctly estimate the size of some text in Javascript. Even if you have complete information of the font metrics and textual content and full power of programming and raw OS API (which you don't have access to in Javascript), this is a notoriously difficult problem, due to font hinting and other complications. And, after all, some code needs to add '…' (by the way, &hellip;, not three dots).

You really need to leave the element self-sizing, depending on the content, and dynamically change the content to show few first words and &hellip;. You can do it with Javascript. For this purpose, you would need to calculate shortened versions of the text and remember those values in the code (this is good to do with Javascript array, which works as the associative container, with O(1) complexity of the search). Then you need to handle hover events (for example; it could be something else, according to your design) to show full or shortened text. The size of the div will be automatically adjusted depending in its inner HTML and CSS (padding).

To handle such events, it's the best to use jQuery, for example: http://api.jquery.com/hover[^].

Calculation of shortened text can be done using the function split():
http://www.w3schools.com/jsref/jsref_split.asp[^].

If you need to learn jQuery (highly recommended), please see:
http://en.wikipedia.org/wiki/JQuery[^],
http://jquery.com[^],
http://learn.jquery.com[^],
http://learn.jquery.com/using-jquery-core[^],
http://learn.jquery.com/about-jquery/how-jquery-works[^] (start from here).

—SA


这篇关于如何隐藏数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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