将值设置为“”后调整文本框大小

时间:2017-09-14 13:15:23

标签: javascript html

我有一个textarea,在输入时会自动增长,而某些JS会在更改选项时清除textarea。但是,当通过JS将值设置为“”时,textarea不会收缩。关于如何让它发挥作用的任何建议?

function clearTextArea(){
	document.getElementById('fldAdditionalInformation').value = "";
}

function auto_grow(element) {
  element.style.height = "0px";
  element.style.height = (element.scrollHeight+10)+"px";
}
<p>Change Value to clear Textbox:
<select onchange="clearTextArea();">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
</p>

<textarea style="width:100%;" id="fldAdditionalInformation" onkeyup="auto_grow(this)"></textarea>

1 个答案:

答案 0 :(得分:3)

清除文本区域后,您应该运行def create_charge @amount = 500 customer = Stripe::Customer.create(email: params[:email]) pay = Stripe::Charge.create( :amount => params[:amount], :currency =>params[:currency], # :source=>params[:token], :customer=>customer.id, # obtained with Stripe.js :description => "Charge for ") send_json_response("Payment","success",{:pay=>pay}) end

&#13;
&#13;
auto_grow
&#13;
function clearTextArea(){
    var element = document.getElementById('fldAdditionalInformation');
    element.value = "";
    auto_grow(element)
}

function auto_grow(element) {
    element.style.height = "0px";
    element.style.height = (element.scrollHeight+10)+"px";
}
&#13;
&#13;
&#13;