好吧,所以我想寫一個簡單的顯示/隱藏內容按鈕,但我想顯示和隱藏使用兩個不同的功能的內容。現在它隱藏得很好,但不會重新顯示。我想改變一個按鈕的onclick使用JavaScript,但它不工作
<html>
<head>
<title>Test</title>
<script type="text/javascript">
function hidecontent(){
document.getElementById("content").style.display = "none";
document.getElementById("hidebutton").value = "+";
document.getElementById("hidebutton").onclick = showcontent();
}
function showcontent(){
document.getElementById("content").style.display = "block";
document.getElementById("hidebutton").value = "-";
document.getElementById("hidebutton").onclick = hidecontent();
}
</script>
<style type="text/css">
#content{
border: 1px solid #003333;
background-color: #000033;
color: #ffffff;
height: 500px;
width: 500px;
text-align: center;
display: block;
}
#hidebutton{
border: 1px solid #003333;
background-color: #000033;
color: #ffffff;
padding: 0px 0px 0px 0px;
margin: 0px 0px 0px 0px;
}
</style>
</head>
<body>
<form>
<input id="hidebutton" type="button" value="-" onclick="hidecontent()" />
</form>
<?php
echo '<div id="content">Hello world!</div>';
?>
</body>
</html>
'hidecontent()'應該沒有尾括號,例如'document.getElementById(「hidebutton」)。onclick = hidecontent;'。這是問題:) – Sarfraz 2010-11-02 06:23:36