Basic Network Troubleshooting
2010-03-31 10:30
399 查看
HTML超出文本多行截取代码如下:
HTML:
<div class="sytm-text-1">
<p>
沈阳网页制作公司有添美科技,网址是:http://www.sytm.net/wangzhanjianshe/
</p>
</div><div class="sytm-text-2">
<p>
沈阳网上商城建设公司有添美科技,网址是:http://www.sytm.net/jiejuefangan/
</p>
</div>CSS:.sytm-text-1 {
color: #FFF;
background: #000;
width: 410px;
height: 22px;
}
.sytm-text-2 {
color: #FFF;
background: #000;
width: 410px;
height: 44px;
}
p {
line-height: 22px;
}JS(引入jQuery):$("div[class*='sytm-text']").each(function(e){
var divHeight = $(this).height();
var $p = $("p", $(this)).eq(0);
while ($p.outerHeight() > divHeight) {
$p.text($p.text().replace(/(\s)*([a-zA-Z0-9]+|\W)(\.\.\.)?$/, "..."));
};
});
通过上述代码可以发现,实现这个效果的主要原理在于通过子容器(p)与父容器(div)高度的比较根据正则表达式进行字符截取,直到两者相等为止。所以控制截取行数的关键自然在div高度上了。
HTML:
<div class="sytm-text-1">
<p>
沈阳网页制作公司有添美科技,网址是:http://www.sytm.net/wangzhanjianshe/
</p>
</div><div class="sytm-text-2">
<p>
沈阳网上商城建设公司有添美科技,网址是:http://www.sytm.net/jiejuefangan/
</p>
</div>CSS:.sytm-text-1 {
color: #FFF;
background: #000;
width: 410px;
height: 22px;
}
.sytm-text-2 {
color: #FFF;
background: #000;
width: 410px;
height: 44px;
}
p {
line-height: 22px;
}JS(引入jQuery):$("div[class*='sytm-text']").each(function(e){
var divHeight = $(this).height();
var $p = $("p", $(this)).eq(0);
while ($p.outerHeight() > divHeight) {
$p.text($p.text().replace(/(\s)*([a-zA-Z0-9]+|\W)(\.\.\.)?$/, "..."));
};
});
通过上述代码可以发现,实现这个效果的主要原理在于通过子容器(p)与父容器(div)高度的比较根据正则表达式进行字符截取,直到两者相等为止。所以控制截取行数的关键自然在div高度上了。
相关文章推荐
- Troubleshooting gc block lost and Poor Network Performance in a RAC Environment (Doc ID 563566.1)
- Network Troubleshooting Using ESXCLI 5.1 (VMware vSphere Blog)
- The Science of Network Troubleshooting
- Solaris: Network Troubleshooting
- CRM Middleware: BDoc basic knowledge and troubleshooting case study
- Internal Only: Advanced Troubleshooting of CSS Heartbeat Failures (Network) (Doc ID 457772.1)
- Troubleshooting Network Teaming Problems with IP Hash
- Basic Fast OSX Troubleshooting
- Know and Understand the Network Troubleshooting Tools Available in Windows 7
- Troubleshooting Network Teaming Problems in ESX/ESXi
- Linux Network Troubleshooting
- Basic Fast OSX Troubleshooting
- cisco network Trouble Shooting
- Sams Teach Yourself Network Troubleshooting in 24 Hours (2nd Edition)
- network issue troubleshooting
- Troubleshooting Certificate Status and Revocation
- Linux troubleshooting tools
- Communicator & Lync Lync Sign-In Troubleshooting Tool (Version 3)