文本通过JavaScript按钮复制后以小写格式呈现。

huangapple go评论93阅读模式
英文:

The text copied with the javascript button format the text in lower case

问题

I'm using a button to copy all text from an "input text area," but I need the text to be in uppercase and the script to format everything in lowercase.

How to make it uppercase?

英文:

I'm using a button to copy all text from an "input text area", but I need the text to be in uppercase and the script to format everything in lowercase.

How to make it uppercase?

  1. function myFunction() {
  2. // Get the text field
  3. var copyText = document.getElementById("myInput");
  4. // Select the text field
  5. copyText.select();
  6. copyText.setSelectionRange(0, 99999); // For mobile devices
  7. // Copy the text inside the text field
  8. navigator.clipboard.writeText(copyText.value);
  9. }

答案1

得分: 2

你可以使用.toLowerCase().toUpperCase()函数来将字符串修改为全小写或全大写。

  1. let text = "this text is fully lower case"
  2. console.log(text.toUpperCase()) // 输出: "THIS TEXT IS FULLY LOWER CASE"
英文:

You can use the .toLowerCase() And .toUpperCase()functions to modify a string to be either fully lower or upper case

  1. let text = "this text is fully lower case"
  2. console.log(text.toUpperCase()) // logs: "THIS TEXT IS FULLY LOWER CASE"
  3. </details>
  4. # 答案2
  5. **得分**: 0
  6. 你可以尝试这样做,看看最后一行的编辑:
  7. ```javascript
  8. function myFunction() {
  9. // 获取文本字段
  10. var copyText = document.getElementById("myInput");
  11. // 选择文本字段
  12. copyText.select();
  13. copyText.setSelectionRange(0, 99999); // 适用于移动设备
  14. // 复制文本字段内的文本
  15. navigator.clipboard.writeText(copyText.value.toLocaleLowerCase()); // 添加这行
  16. }
英文:

You can try this, see the edit in last line:

  1. function myFunction() {
  2. // Get the text field
  3. var copyText = document.getElementById(&quot;myInput&quot;);
  4. // Select the text field
  5. copyText.select();
  6. copyText.setSelectionRange(0, 99999); // For mobile devices
  7. // Copy the text inside the text field
  8. navigator.clipboard.writeText(copyText.value.toLocaleLowerCase()); // Add this
  9. }

huangapple
  • 本文由 发表于 2023年5月14日 18:51:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76247070.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定