标签:
*下面封装的监控TEXT VAL 值 的函数*/ $.event.special.valuechange = { teardown: function (namespaces) { $(this).unbind(‘.valuechange‘); }, handler: function (e) { $.event.special.valuechange.triggerChanged($(this)); }, add: function (obj) { $(this).on(‘keyup.valuechange cut.valuechange paste.valuechange input.valuechange‘, obj.selector, $.event.special.valuechange.handler) }, triggerChanged: function (element) { var current = element[0].contentEditable === ‘true‘ ? element.html() : element.val() , previous = typeof element.data(‘previous‘) === ‘undefined‘ ? element[0].defaultValue : element.data(‘previous‘) if (current !== previous) { element.trigger(‘valuechange‘, [element.data(‘previous‘)]) element.data(‘previous‘, current) } } }
用法:
$(‘.edit-word-text‘).on(‘valuechange‘, function (e, previous) { /*$(‘#output‘).append(‘previous: ‘ + previous + ‘ -- current: ‘ + $(this).val() + ‘<br />‘)*/ $("#canvas").find(".page").find(".fontAtHover").html($(this).val()) })
标签:
原文地址:http://www.cnblogs.com/yjhua/p/4806995.html