在本地机器上,我的简单js验证可以工作,但在jsfiddle上却不行;t为什么

on local machine my simple js validation works but on jsfiddle it doesn't why?

本文关键字:jsfiddle 但在 为什么 工作 机器 我的 简单 验证 js      更新时间:2023-09-26

请在以下链接中查看我的链接http://jsfiddle.net/3908050/n6g33gqo/3/我不知道发生了什么,可能是因为我是js小提琴的新手

 <form onsubmit='return formValidator()'>First Name:
        <input type='text' id='firstname' />
        <br />Address:
        <input type='text' id='addr' />
        <br />Zip Code:
        <input type='text' id='zip' />
        <br />State:
        <select id='state'>
            <option>Please Choose</option>
            <option>AL</option>
            <option>CA</option>
            <option>TX</option>
            <option>WI</option>
        </select>
        <br />Username(6-8 characters):
        <input type='text' id='username' />
        <br />Email:
        <input type='text' id='email' />
        <br />
        <input type='submit' value='Check Form' />
    </form>

这是因为您将formValidator()函数放在$(document).ready内,因此它不再在全局范围内,并且无法从onsubmit 等内联事件处理程序访问

您并没有真正使用jQuery,所以只需删除DOM就绪处理程序

FIDDLE