JavaScript判斷輸入內容不能全為空格的方法,用來避免輸入框的內容輸入的全是空格:
復制代碼 代碼如下:
<html>
<head>
<script>
function checkBlankSpace(str){
while(str.lastIndexOf(" ")>=0){
str = str.replace(" ","");
}
if(str.length == 0){
alert("輸入不能全為空");
}
}
function test(){
var testStr = document.getElementById("test").value;
checkBlankSpace(testStr);
}
</script>
</head>
<body>
<input type="text"/>
<input type="button" value="測試">
</body>
</html>
新聞熱點
疑難解答
圖片精選