Add more different ID or CLASS into same $( )
(As I have issues with mozilla, I have to empty FORM after submission.)
At submit I need to empty FORM values. Is there a neater and simpler way of doing this?
$('#name').val(''); // empty form input
$('#comment').val(''); // empty form textarea
$('#email').val(''); 开发者_运维知识库 // empty form input
something as: (wrong)
$('#name','#comment','#email').val('');
The plain form .reset()
help method is there for you. Since this method is a native "DOM" method from HTMLInputElement
you need to grab the DOMNode
from the jQuery object. That can be accomplished by invoking .get(0)
help (which grabs the first element from the jQuery array-like-object) or just access it with brackets.
$('form')[0].reset();
demo: http://www.jsfiddle.net/53SRZ/
Another option is to use a selector like
$('form input').val('');
If you don't have the requirement to only clear specific elements.
You use the comma to separate not your function arguments but your selectors. All your selectors go in one string argument:
$('#name, #comment, #email').val('');
Try $('#name, #comment, #email').val('');
.
The quotations are supposed to enclose EVERYTHING you're selecting. You're telling jQuery what is essentially a CSS selection, and the whole block #name, #comment, #email
is a valid CSS selector.
You wrote:
$('#name','#comment','#email').val('');
Close, but not quite. The correct solution is simply to put them all into the same string, like this:
$('#name, #comment, #email').val('');
精彩评论