html:
<p><span>JavaScript 是属于网络的脚本语言!...</span><a href="javascript:;">>>收缩</a></p>
css:
a {text-decoration: none;}/* 去掉a的默认下划线*/
js:
var oP = document.getElementsByTagName('p')[0];
var oSpan = document.getElementsByTagName('span')[0];
var oA = document.getElementsByTagName('a')[0];
var str = oSpan.innerHTML;//获取文字内容,方便隐藏和显示
var onOff = true;//开关
oA.onclick = function(){
if(onOff){
oSpan.innerHTML = str.substring(0,18);
oA.innerHTML = '......>>展开';
}else{
oSpan.innerHTML = str;
oA.innerHTML = '<<收缩';
}
onOff = !onOff;//每次点击之后都取反
};