[英]How can I set current typed characters manually on bootstrap maxlength?
https://jsfiddle.net/0tx58ma1/6/ 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>
This plugin counts the number of characters currently typed in real time.该插件实时计算当前输入的字符数。
If you are typing with a keyboard, it will count the number of characters as you expect.如果您使用键盘打字,它会按您的预期计算字符数。
However, if you substitute a string with a click event using jQuery, it will not count the number of characters because it is not typing.但是,如果您使用 jQuery 将字符串替换为单击事件,则不会计算字符数,因为它没有输入。
I would like the current character count to appear in the character counters when the button is clicked.我希望单击按钮时当前字符数出现在字符计数器中。
I wanna set current typed characters when I push button.当我按下按钮时,我想设置当前输入的字符。 How can I???
我怎样才能???
I heard the solution to this problem from developer.我从开发人员那里听到了这个问题的解决方案。
It seems that we can count the number of characters by doing the following.似乎我们可以通过执行以下操作来计算字符数。
$("#test").val("ypaaaa")
to
$("#test").val("ypaaaa").trigger('input')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.