Javascript:文本区域的最后一个字符未大写

时间:2019-06-03 19:13:48

标签: javascript html css shopify

编辑Shopify应用。除非您在文本区域之外单击,否则文本区域中的最后一个字符不会在标签图片上大写。

$(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>

2 个答案:

答案 0 :(得分:2)

您可能正在寻找与keyup不同的事件。 input最适合您要执行的imo。

$(function() {
    $('#cstedit-addembossing').on("input", function() {
        this.value = this.value.toUpperCase();
    });
});

答案 1 :(得分:0)

// 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>

要解决此问题,请继续:

// 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>