定义一个长度嘛 Sting s="这是新闻标题哈哈哈哈哈哈哈哈"; int lengt=s.length(); if (int>10) s=s.substring(0,10)+"...";
substring(int beginIndex, int endIndex) Returns a new string that is a substring of this string. 用这个方法试下
我忘记说了 条件是不在服务器端进行 用css或脚本怎么弄啊? 谢谢
刚好在人家blog(http://www.mysheji.com/blog/article.asp?id=304)上看到过 ====== <% function cLeft(str,n) dim str1,str2,alln,Islefted str2 = "" alln = 0 str1 = str Islefted = false if isnull(str) then cleft = "" exit function end if for i = 1 to len(str1) nowstr = mid(str1,i,1) if asc(nowstr)<0 then alln = alln + 2 else alln = alln + 1 end if if (alln<=n) then str2 = str2 & nowstr else Islefted = true exit for end if next if Islefted then str2 = str2 & ".." end if cleft = str2 end function %> ======不过不好意思,是VBS的
脚本还是一样的道理嘛。。<body onload="gai();"> <span id ="new1">我是新闻哈哈哈哈哈哈哈哈哈哈我行了吗</span> <body> <SCRIPT LANGUAGE="JavaScript"> function gai() { if (new1.innerText.length>10) { var s =new1.innerText.substring(0,10); new1.innerText=s+"..."; } } </SCRIPT>记得把你新闻的标题弄成<span>标签之间
Sting s="这是新闻标题哈哈哈哈哈哈哈哈";
int lengt=s.length();
if (int>10)
s=s.substring(0,10)+"...";
Returns a new string that is a substring of this string.
用这个方法试下
条件是不在服务器端进行
用css或脚本怎么弄啊?
谢谢
======
<%
function cLeft(str,n)
dim str1,str2,alln,Islefted
str2 = ""
alln = 0
str1 = str
Islefted = false
if isnull(str) then
cleft = ""
exit function
end if
for i = 1 to len(str1)
nowstr = mid(str1,i,1)
if asc(nowstr)<0 then
alln = alln + 2
else
alln = alln + 1
end if
if (alln<=n) then
str2 = str2 & nowstr
else
Islefted = true
exit for
end if
next
if Islefted then
str2 = str2 & ".."
end if
cleft = str2
end function
%>
======不过不好意思,是VBS的
<span id ="new1">我是新闻哈哈哈哈哈哈哈哈哈哈我行了吗</span>
<body>
<SCRIPT LANGUAGE="JavaScript">
function gai()
{
if (new1.innerText.length>10)
{
var s =new1.innerText.substring(0,10);
new1.innerText=s+"...";
}
}
</SCRIPT>记得把你新闻的标题弄成<span>标签之间