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

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

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?

function myFunction() {
        // Get the text field
        var copyText = document.getElementById("myInput");
        // Select the text field
        copyText.select();
        copyText.setSelectionRange(0, 99999); // For mobile devices
        // Copy the text inside the text field
        navigator.clipboard.writeText(copyText.value);
}

答案1

得分: 2

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

let text = "this text is fully lower case"

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

let text = "this text is fully lower case"

console.log(text.toUpperCase()) // logs: "THIS TEXT IS FULLY LOWER CASE"


</details>



# 答案2
**得分**: 0

你可以尝试这样做,看看最后一行的编辑:

```javascript
function myFunction() {
        // 获取文本字段
        var copyText = document.getElementById("myInput");
        // 选择文本字段
        copyText.select();
        copyText.setSelectionRange(0, 99999); // 适用于移动设备
        // 复制文本字段内的文本
        navigator.clipboard.writeText(copyText.value.toLocaleLowerCase()); // 添加这行
}
英文:

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

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

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:

确定