这个问题已经得到了回答,但是为了以后的参考,这里提供一个完整的示例。
您可以点击添加按钮和清除按钮,无论点击多少次都能够正常工作。但是一旦在文本框中输入内容,清除和添加按钮就不再起作用。
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#add").click(function(){
$("#box").append("Test, ")
});
$("#clean").click(function(){
$("#box").text("")
});
});
</script>
</head>
<body>
<button id="add">ADD</button><br/>
<textarea rows="10" cols="50" id="box"></textarea><br/>
<button id="clean">Clear Box</button>
</body>
</html>