0

我需要你的帮助,

当我重新单击“展开”按钮时,如何重新最小化(将 textarea 的类设置为正常)

我可以让它工作,但不能反过来。

这是我的 HTML + Javascript

<!DOCTYPE html>

<html>

<head>

<style type="text/css">
.normal {
    width: 400px;
    height: 25px;

}
.expand {
    height: 400px;
    width: 400px;
}
</style>

<script type="text/javascript">
function expand() {

document.getElementById('subject_area').className = "expand"

document.getElementById('expand').value = "minimize"


}
</script>

</head>

<body>
<input class="normal" id="subject_area" type="textarea" >
<input id="expand" type="button" value="expand" onclick="expand()">
</body>

</html>
4

2 回答 2

0

你可以做:

var subject = document.getElementById('subject_area');
var btnExpand = document.getElementById('expand');
subject.className == "expand" ? subject.className = "normal" : subject.className = "expand";
btnExpand.value == "minimize" ? btnExpand.value = "expand" : btnExpand.value = "minimize";
于 2013-10-15T18:33:08.597 回答
0
var subject = document.getElementById('subject_area');
var button = document.getElementById('expand');

function expand() {
    if (subject.className === 'normal') {
        subject.className = 'expand';
        button.value = 'minimize';
    } else {
        subject.className = 'normal';
        button.value = 'expand';
    }
}

在这里小提琴:http: //jsfiddle.net/ToddT/aPqgh/

于 2013-10-15T18:37:41.940 回答