简体   繁体   中英

JavaScript value of an empty form field

I want to validate an HTML form to ensure an <input> has a value. In JavaScript, what is the value of an empty field in a form: null or the empty string ( "" )?

For any input element, value is always a string. This means you can expect it to be "" , when empty.

See the docs for HTMLInputElement on the Mozilla Developer Network, or the relevant part of the HTML4 spec .

Empty string, if it's a text field.

It's an empty string -- one of the beautiful perks of JavaScript.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM