簡體   English   中英

在textarea中插入時更改其他文本

[英]on insert in textarea change other text

我喜歡在texarea插入文本時更改不同的內容。 例如,如果我在textarea輸入任何文本,則id=resid=res2應該更改為靜態數字。 表示"-.-"應為"2.0"

謝謝

HTML

<textarea id="inptxt" ></textarea>
<div id="res" >-.-</div>
<div id="res2">-.-</div>

JS

$("#inptxt").on("change input paste keyup", function() {
  $("#res").html(jQuery(this).val());
  $("#res2").html(jQuery(this).val());
});

或看這里: jsfiddle

您可以使用parseFloat函數http://jsfiddle.net/vineeshmp/ZVcG4/40/

$("#inptxt").on("change input paste keyup", function() {   
    $("#res").html(jQuery(this).val()?'2.0':'-.-');
    $("#res2").html(jQuery(this).val()?'2.0':'-.-');
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM