我想添加一个隐藏按钮来设置div的默认大小,当点击更多时,它会用隐藏按钮替换更多按钮
<script type="text/javascript" language="javascript">
function resizeDiv(id) {
var obj = document.getElementById(id);
if (obj) {
obj.setAttribute("style", "height:600px;");
}
}
</script>
<button style="margin:10px;" onclick="javascript:resizeDiv('ss');
">More</button>
答案 0 :(得分:0)
你可能意味着这个
<style type="text/css">
#ss { display:none }
</style>
<script type="text/javascript">
window.onload=function() {
document.getElementById("butss").onclick=function() {
var obj = document.getElementById(this.id.replace("but",""));
if (obj) {
var on = this.innerHTML=="More";
obj.style.display=(on)?"block":"none"; // or obj.style.height=(on)?"600px":"0";
this.innerHTML=(on)?"Less":"More";
}
}
}
</script>
<button style="margin:10px;" id="butss">More</button>
<div id="ss">Hello</div>
答案 1 :(得分:-1)
这样的事情:
<button style="margin:10px;" onclick="javascript:resizeDiv('ss');if (this.innerHTML == 'More') {this.innerHTML = 'Hide'} else {this.innerHTML = 'Hide'}">More</button>