StringBuffer.jsfunction StringBuffer(string)
{
this._string=new Array(string);
}
StringBuffer.prototype=
{
append:function(string)
{
this._string.push(string);
},
showString:function()
{
return this._string.join(",");
}
}index.html<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript" src="StringBuffer.js">
var sb=new StringBuffer("第一");
function add()
{
var txtStr=document.getElementById("txtName").value;
sb.append(txtStr);
}
function show()
{
document.getElementById("divShow").value=sb.showString();
}
</script>
</head><body><form action="" method="get">
<input name="txtName" id="txtName" type="text" />
<input onclick="add()" type="button" value="add" />
<input onclick="show()" type="button" value="show" />
<div id="divShow"></div>
</form>
</body>
</html>点击add时有错误:22行缺少对象
怎么会缺少对象呢?