[英]Javascript: Text area last character is not being capitalized
Editing a Shopify app. 编辑Shopify应用。 Last character in the text area does not get capitalized on the label picture unless you click outside of text area.
除非您在文本区域之外单击,否则文本区域中的最后一个字符不会在标签图片上大写。
$(function() { $('#cstedit-addembossing').keyup(function() { this.value = this.value.toUpperCase(); }); });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <textarea maxlength="10" data-area="back" class="customify-text" data-target="addembossing" id="cstedit-addembossing" placeholder="Write a name, special date, quote, and the list goes on"></textarea>
You probably are looking for a different event than keyup
. 您可能正在寻找与
keyup
不同的事件。 input
works best for what you are trying to do imo. input
最适合您要进行imo的操作。
$(function() {
$('#cstedit-addembossing').on("input", function() {
this.value = this.value.toUpperCase();
});
});
// those listeners are added by customizer-final-v33.js foo.addEventListener('change', e => display.textContent = foo.value); foo.addEventListener('input', e => display.textContent = foo.value); // this is basically your listener foo.addEventListener('keyup', e => foo.value = foo.value.toUpperCase());
<textarea id="foo"></textarea> <hr /> <h1 id="display">Type and texarea will update this text.</h1>
To fix that, here you go: 为了解决这个问题,您可以在这里进行以下操作:
// those listeners are added by customizer-final-v33.js foo.addEventListener('change', e => display.textContent = foo.value); foo.addEventListener('input', e => display.textContent = foo.value); // this is basically a working version your listener foo.addEventListener('keydown', (e) => { event.preventDefault(); foo.value = foo.value + String.fromCharCode(e.keyCode).toUpperCase(); foo.dispatchEvent(new CustomEvent('input', { bubbles: true })); })
<textarea id="foo"></textarea> <hr /> <h1 id="display">Type and texarea will update this text.</h1>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.