javascriptは入力が空かどうかを判断します.

980 ワード

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<h2>      </h2>
<input type="text" id="strs" value="            ">
<input type="button" id="isContent" value="      ">
<script>
    window.onload=function(){
        var text=document.getElementById("strs"),
             btn=document.getElementById("isContent");
        btn.onclick=function(){
            var textval=text.value;
                var trimspaceval=textval.replace(/(\s|\u00A0)+|(\s|\u00A0)/g,"");
                text.value=trimspaceval;
            if(!trimspaceval){
                alert("      !");
            }
            else {
                alert("       !");
            }
        }
    }
</script>
</body>
</html>