簡體   English   中英

jQuery .change 不起作用

[英]jQuery .change doesn't work

為什么當我改變輸入時輸出沒有改變?

HTML

<div class="display" id="out">test</div>

<div class="form-group">
  <label for="comment">value:</label>
  <input class="form-control" type="text" value="0.00" id="in"></input>
</div>

jQuery

$('#in').on("change", function(){
    $('#out').html($(this).val());
});

http://jsfiddle.net/ahpu8wwx/2/

您的小提琴中缺少 jQuery 庫。 使用inputkeyup事件進行即時更新。 僅當您從輸入字段聚焦時才會觸發change事件

 $('#in').on("input", function(){ $('#out').html(this.value); });
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div class="display" id="out">test</div> <div class="form-group"> <label for="comment">value:</label> <input class="form-control" type="text" value="0.00" id="in"/> </div>

代碼有效,請確保您已包含 jQuery。 在此處輸入圖片說明

暫無
暫無

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

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