簡體   English   中英

如何在引導程序 maxlength 上手動設置當前鍵入的字符?

[英]How can I set current typed characters manually on bootstrap maxlength?

https://jsfiddle.net/0tx58ma1/6/

 (function($){ $('[maxlength]').maxlength({ alwaysShow: true, separator: ' / ', preText: '', postText: '', showMaxLength: true, showCharsTyped: true, placement: 'bottom-right-inside', showOnReady: true, }); $("#btnReplaceText").click(function(){ $("#test").val("ypaaaa"); $("#text").show(); }); })(jQuery);
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.0-alpha1/js/bootstrap.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-maxlength/1.10.0/bootstrap-maxlength.min.js"></script> <input type="text" id="test" maxlength="10" placeholder="please click button" value=""> <br> <button type="button" id="btnReplaceText">click me</button> <p id="text" style="display: none;">I wanna set current typed characters when I push button. How can I???</p>

該插件實時計算當前輸入的字符數。

如果您使用鍵盤打字,它會按您的預期計算字符數。

但是,如果您使用 jQuery 將字符串替換為單擊事件,則不會計算字符數,因為它沒有輸入。

我希望單擊按鈕時當前字符數出現在字符計數器中。

當我按下按鈕時,我想設置當前輸入的字符。 我怎樣才能???

我從開發人員那里聽到了這個問題的解決方案。

似乎我們可以通過執行以下操作來計算字符數。

$("#test").val("ypaaaa") 

to

$("#test").val("ypaaaa").trigger('input') 

暫無
暫無

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

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