我在 5 到 10 分钟前才刚刚开始学习 JS,有人告诉我尝试创建一个基本的验证功能,但它似乎没有按预期工作。它检查字段是否为空,该部分有效。但是检查它是否有东西并继续运行代码没有。
我的表格:
echo '<form action="index.php?action=getHashedText" method="post"     name="formHash">
        <br/><textarea name="text" rows="4" cols="50" placeholder="Add your text/pharse/word which you want hashing here." autofocus></textarea><br/>
        <button type="button" name="button" onclick="return validate();">Hash</button>';
函数验证():
    <script>
    function validate() {
        with (window.document.formHash) {
            if (formHash.text.value === "") {
                    alert('Field is empty!');   
                    return false;
            } else {
                    return true;
            }    
        }  
    }
    </script>