English 中文(简体)
如何利用 j的形式清除所有投入、选择和隐藏的田地?
原标题:How to clear all inputs, selects and also hidden fields in a form using jQuery?

I would like to clear all inputs, selects and also all hidden fields in a form. Using jQuery is an option if best suited.

这样做的最容易的方法...... 我指的是容易理解和维护的。

<><>>

解决办法不应带有检查箱(必须保持其价值,但必须清除检查状态),也不应有提交纽州。

我试图做的是清楚的纽芬兰语,这明确了用户明确提出的所有选择,并指明了隐蔽的领域。

感谢!

最佳回答

您可使用reset(。 方法:

$( #myform )[0].reset();

或无 j:

document.getElementById( myform ).reset();

<代码>myform为表格的复制件,其中载有你希望清除的内容。

也可使用:input 。 选择田地不位于形式:

$( :input ).val(  );
问题回答

清除所有投入,包括隐蔽的田地,使用JQuery:

// Behold the power of JQuery.
$( input ).val(  );

选择更困难,因为它们有固定名单。 您要明确这一清单,或只是选择。

可能的话

$( option ).attr( selected , false);
$( #formID )[0].reset(); // Reset all form fields

如果你想对特定领域适用明确价值,则向它们分配补贴或分类,并对它们适用空值。 类似:

$( .all_fields ).val(  );

where all_fields is class applied to desired input fields for applying empty values. It will protect other fields to be empty, that you don t want to change.

我有一个稍加专门化的案件,这是一个搜索表,其输入工具可以自动填写个人名称。 Java字母代码列出了一种隐性投入, from.reset()并不明确。

然而,我不想重开所有隐藏的投入。 我在其中添加了一个类别,即<代码>search- Value,以输入有待清除的隐藏材料。

$( form#search-form ).reset();
$( form#search-form input[type=hidden].search-value ).val(  );

供所有输入标的,如投入、电子、文本等。 简称

$( #message ).val(  ).change();

你们可以把这一点列入你的分类法,或者可以单独行事:

window.onload = prep;

function prep(){
document.getElementById( somediv ).onclick = function(){
document.getElementById( inputField ).value =  ;
  }
}




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签