我想用下面的代码自动设置多文本、文本框的高度但不起作用
//behind Code
TextBox txt = new TextBox();
txt.TextMode = TextBoxMode.MultiLine;
txt.Text = ...
txt.ID = ...
txt.ReadOnly = true;
Page.ClientScript.RegisterStartupScript(this.GetType(), "changeSHeight", "changeSHeight('" + txt.ClientID + "');", true);
//javascript
<script type="text/javascript">
function changeSHeight(f)
{
var e = document.getElementById(f);
e.style.height = e.scrollHeight + "px";
}
</script>
我检查changeSHeight
它是否被正确调用
当我想显示scrollHeight
时alert
不显示任何内容,问题是因为我从后面的代码中添加了文本框,这一行:var e = document.getElementById(f);
找不到它们