How to reset (clear) form through JavaScript?

2019-01-02 17:56发布

I have tried $("#client.frm").reset(); but it is not working.So how to reset form via jQuery?

11条回答
萌妹纸的霸气范
2楼-- · 2019-01-02 18:21

Reset (Clear) Form throught Javascript & jQuery:

Example Javascript:

document.getElementById("client").reset();

Example jQuery:

You may try using trigger() Reference Link

$('#client.frm').trigger("reset");
查看更多
妖精总统
3楼-- · 2019-01-02 18:23

You could use the following:

$('[element]').trigger('reset')
查看更多
谁念西风独自凉
4楼-- · 2019-01-02 18:25

Use JavaScript function reset():

document.forms["frm_id"].reset();
查看更多
泪湿衣
5楼-- · 2019-01-02 18:26

,reset() method does not clear the default values and checkbox field and there are many more issues.

In order to completely reset check the below link -

http://www.javascript-coder.com/javascript-form/javascript-reset-form.htm

查看更多
看淡一切
6楼-- · 2019-01-02 18:28

You can simply do:

$("#client.frm").trigger('reset')

查看更多
孤独寂梦人
7楼-- · 2019-01-02 18:35

form.reset() is a DOM element method (not one on the jQuery object), so you need:

$("#client.frm")[0].reset();
//faster version:
$("#client")[0].reset();

Or without jQuery:

document.getElementById("client").reset();
查看更多
登录 后发表回答