textarea高度自增
用法 $("textarea").txtaAutoHeight();
$.fn.extend({
txtaAutoHeight: function () {
return this.each(function () {
var $this = $(this);
if (!$this.attr('initAttrH')) {
$this.attr('initAttrH', $this.outerHeight());
}
setAutoHeight(this).on('input', function () {
setAutoHeight(this);
});
});
function setAutoHeight(elem) {
var $obj = $(elem);
return $obj.css({ height: $obj.attr('initAttrH'), 'overflow-y': 'hidden' }).height(elem.scrollHeight);
}
}
});
JS替换模板
function replace_tmp(tmp_str,data){
var reg=new RegExp("~(.*?)~","g");
tmp_str=tmp_str.replace(reg,function(a,b){
if(typeof(data[b])=='undefined' || !data[b] || data[b]=='undefined'){
return "";
}
return data[b]; });
return tmp_str;
}