[英]How can I convert to text I collect from these input fields to lower case in Javascript?
[英]How can I convert text typed in an input box to lower case?
我不知道如何將鍵入到文本輸入框(txtQuestion)的文本轉換為全部小寫,即鍵入“ input”或“ INpUt”將被讀取並輸出相同的結果。
使用toLowerCase()函數。 例如: "INPuT".toLowerCase();
exampleFunction = function(){ //First we get the value of input var oldValue = document.getElementById('input').value; //Second transform into lowered case var loweredCase = oldValue.toLowerCase(); //Set the new value of input document.getElementById('input').value = loweredCase; }
<input id="input" type="text" onkeyup="exampleFunction()" />
您必須選擇要觀看的事件,然后將相同值但小寫的返回到輸入:
function InputLowerCaseCtrl(element, event) { console.log(element.value) return element.value = (element.value || '').toLowerCase(); }; InputLowerCaseCtrl.bindTo = ['blur'].join(' '); document.addEventListener('DOMContentLoaded', function() { var input = document.querySelector('.input-lowercase'); return input.addEventListener(InputLowerCaseCtrl.bindTo, InputLowerCaseCtrl.bind(this, input)); });
<input class="input-lowercase" type="text" />
您可以使用String.prototype.toLowerCase函數將任何字符串輸入轉換為小寫
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase
對於您而言,帶有txtQuestion輸入的示例。
var inputStringLowerCase = inputTxtQuestion.value.toLowerCase();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.