javascript - jQuery: use var shortcut to assign data and how to chain function to run on load and click -
i've got two-part question.
one: can use last
variable set update value on line after if (!last) {
? i.e., last = size;
?
var j$ = jquery.noconflict(); function updatecount() { var self = j$(this), last = self.data('last'), size = self.val().length, span = j$('.currentcount'); if (!last) { self.data('last', size); } else if (last != size) { span.text(size); self.data('last', size); } } j$('textarea[id$=textbody]').on('propertychange change click keyup input paste', updatecount);
secondly, can chain .on('propertychange ...
line have updatecount
run script loaded?
question 1:
no, can not use assignment variable because there no data-binding in jquery. updating last
variable never update data-last
of jquery object.
question 2:
this used do:
j$('textarea[id$=textbody]').on('propertychange change ...', updatecount).change();
where change()
automatically triggers function.
Comments
Post a Comment