简体   繁体   English

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

[英]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.

相关问题 文本区域JavaScript中的字符数限制-特殊情况 - Character Limit In Text Area JavaScript - Special Case 检测文本区域是否与javascript一起使用 - detect whether a text area is being used with javascript 如何替换文本区域字段中的最后一个字符? - How do I replace the very last character in a text area field? 构建 Javascript 正则表达式,期望第一个字符大写,rest 不区分大小写 - Build Javascript regex that expects the first character to be capitalized, case insensitive for the rest 如何使用 JavaScript 或其他方法删除从一个字段复制到另一个字段的某些文本中的最后一个字符? - How do I remove the last character in some text being copied from one field to another using JavaScript or other methods? 文本区域未呈现 - Text area not being rendered 使用javascript / jquery删除&#39;/&#39;字符的最后一次迭代之前的所有文本 - Remove any text before the last iteration of a '/' character with javascript / jquery jQuery文本区域字符数 - JQuery text area character count 当我使用正确的代码触发按键事件时,为什么没有在文本区域上写入空格字符? - Why is space character not being written on the text area when I am firing the keypress event with the correct code? 如何按javascript中的最后一个数字字符对文本数组进行排序 - how do I sort a array of text by the last numberic character in javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM