英文:
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("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.toLocaleLowerCase()); // Add this
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论