标签:style blog color io java ar for 2014 问题
假如我的HTML中有一个textarea元素,我想在它加载完成后根据内容调整其高度。怎么做呢?
1. 我定义的textarea元素如下
<textarea class="form-control" type="text" name="value" id="value"
placeholder="输入参数值"></textarea>注意: id = ‘value‘
这里的关键问题是html加载完后会调用哪个函数,有以下两种方法:
2.1 方法一:通过调用$(document).ready(function () {} )
<script type="text/javascript">
function get_text_rows(text) {
return text.split("\n").length;
}
$(document).ready(function () {
document.getElementById('value').rows = get_text_rows($('#value').val());
});
</script><script type="text/javascript">
function get_text_rows(text) {
return text.split("\n").length;
}
window.onload = function() {
document.getElementById('value').rows = get_text_rows($('#value').val());
}
</script>HTML页面加载完后,根据内容调整<textarea>元素的高度
标签:style blog color io java ar for 2014 问题
原文地址:http://blog.csdn.net/loveaborn/article/details/39102695