jquery append方法无效

<script type="text/javascript">
function append(){
$("#text").append("hello world!");
}

function rest(){
$("#text").val("");
}
</script>
</head>
<body>
<button onclick="append()">添加</button>
<button onclick="rest()">重置</button>
<textarea id="text" rows="10" cols="100">
</textarea>

</body>

点了重置再点添加就无效了,这是为什么?

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script class="jquery library" src="/js/sandbox/jquery/jquery-1.8.2.min.js" type="text/javascript"></script>
<title>
RunJS 演示代码
</title>
<script type="text/javascript">
function append(){
$("#text").append("hello world!");
}

function rest(){
$("#text").html("");// 改为html即可
}
</script>
</head>
<body>
<button onclick="append()">
添加
</button>
<button onclick="rest()">
重置
</button>
<textarea id="text" rows="10" cols="100"></textarea>
</body>
</html>追问

谢谢~~~ 但是我这里是想使用追加不想替换,请问有没有别的办法解决呢?

追答

因为你开始用append追加,表示对textarea的内嵌html进行追加;
然而后面你又对他的value进行清空,无视内嵌html的存在,矛盾产生。

所以要统一,要么都对html操作,要么都对value操作,这样就ok了

RunJS 演示代码

function append(){
$("#text").val($("#text").val()+"hello world!");
}

function rest(){
$("#text").val("");
}

添加

重置

温馨提示:答案为网友推荐,仅供参考
相似回答