【发布时间】:2020-07-14 15:40:07
【问题描述】:
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 将字符串替换为单击事件,则它不会计算字符数,因为它没有输入。
我希望在单击按钮时当前字符数显示在字符计数器中。
我想在按下按钮时设置当前输入的字符。我怎么能???
【问题讨论】:
-
能否请您更清楚地说明您的问题陈述?
标签: javascript html jquery twitter-bootstrap