我正在使用SirTrevorJs (http://madebymany.github.io/sir-trevor-js),我想在每个SirTrevor上添加一个字母计数器。
目前,我甚至无法检测到对SirTrevor的关注。如果有人在我得到解释之前就这么做了。
var $st = $('[data-type="sirtrevor"]');
$st.on('focusin', function() {
console.log('ok');
});谢谢,祝您今天愉快!
编辑:
感谢D.坎塔托雷的焦点!
有一个完整的代码工作!
var $st = $('.st-ready');
$.each($st, function() {
var $self = $(this);
$self.on('focusin', function() {
var $this = $(this);
var $textBlock = $this.find('.st-text-block');
$this.on('keyup', function() {
var i = 0;
$.each($textBlock, function() {
i += $(this).text().length;
});
console.log('There is ' + i + ' letters in the SirTrevor');
});
});
});发布于 2016-08-26 18:10:29
我向文本框的类中添加了focusin元素,从而添加了您要寻找的功能。还添加了一个计数器,但您需要解决如何将其绑定到每个文本框。
http://codepen.io/dcantatore/pen/BzXNPX
var i = 0
$('.st-ready').focusin(function() {
$(this).keyup(function(e) {
i++;
console.log(i)
})
}); https://stackoverflow.com/questions/39168611
复制相似问题