我要在一个页面多次执行这段JS该怎么定义接收的值

来源:百度知道 编辑:UC知道 时间:2024/07/08 11:28:40
这是一段折叠代码 我想要写在论坛帖子页面 平时对JS不精通

请问各位怎么去定义!

这段代码 一个页面出现一次 是正常的 但是出现两次就不显示了

我想应该是要顺序定义一个值吧 具体哪个不了解 所以请求帮助!

<style>
#content {
font-size: 14px;
width: 200px;
height: 50px;
background: #eee;
padding: 10px;
border: 4px #ccc double;
overflow: hidden;
}
#key {
color: red;
float: right;
border:1px #ccc solid;
padding:5px;
cursor:hand;
}
</style>
<script>
var s=5;
var minheight=50;
var maxheight=350;
function shoppingcat(){
var key = document.getElementById("key").innerText;
if(key=="展开"){
content.style.pixelHeight+=s;
if(content.style.pixelHeight<maxheight){
setTimeout("shoppingcat();",1);
}else{
document.getElementById("key").innerText="关闭";
}
}else{
content.style

帮你改了一下...你试下

代码:

<style>
.content {
font-size: 14px;
width: 200px;
height: 50px;
background: #eee;
padding: 10px;
border: 4px #ccc double;
overflow: hidden;
}
.key {
color: red;
float: right;
border:1px #ccc solid;
padding:5px;
cursor:hand;
}
</style>
<script>
function shoppingcat(obj,s,minheight,maxheight){
var key = obj.innerText;
var content=obj.parentNode;
if(key=="展开"){
content.style.pixelHeight+=s;
if(content.style.pixelHeight<maxheight){
setTimeout("shoppingcat(document.all["+obj.sourceIndex+"],"+s+","+minheight+","+maxheight+");",1);
}else{
obj.innerText="关闭";
}
}else{
content.style.pixelHeight-=s;
if(content.style.pixelHeight>minheight){
setTimeout("shoppingcat(docume