<div> <input type="text" name="textfield" id="sourceString"> <input type="text" name="textfield" id="resultString"> </div> <div> <input type="button" name="button" id="button1" value="转换为小写"οnclick="changeToL()"> <input type="button" name="button" id="button2" value="转换为大写"οnclick="changeToU()"> <input type="button" name="button" id="button3" value="判断转换为大小写"οnclick="textToLorU()"> </div> <script> function ToL(str) { str= str.toLowerCase(); return str; } function ToU(str) { str= str.toUpperCase(); return str; } function textToLorU(){ var str=document.getElementById("sourceString").value; if(/^[0-9A-Z]*$/.test(str)){ alert("全是大写"); }else if (/^[0-9a-z]*$/.test(str)){ alert("全是小写"); }else{ alert("其中有大写有小写"); } } function changeToL(){ var str=document.getElementById("sourceString").value; str= ToL(str); var ID=document.getElementById("resultString"); ID.value=str; } function changeToU(){ var str=document.getElementById("sourceString").value; str= ToU(str); var ID=document.getElementById("resultString"); ID.value=str; } </script>
js正则表达式判断大小写
最新推荐文章于 2022-09-04 14:34:28 发布