单击按钮清除输入字段 [英] Clear Input Fields on button click

查看:24
本文介绍了单击按钮清除输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个输入字段,用户可以在其中输入数据.单击其中任何一个或两个输入字段都会重置时,它旁边有 2 个按钮.现在,由于这些按钮和字段不在表单内,因此我无法使用 JQuery 清除它.关键是,现在我只显示了 2 个按钮,如果有更多按钮,JQuery 也必须工作......下面的 Fiddle 链接和我试过的代码

I have got a input field where in user enters data. There are 2 buttons next to it upon click any one of them or both the input fields get reset. Now since these buttons and field is not inside a form I can't go for a instead how can i clear it with JQuery. The point is, now I have displayed only 2 buttons, the JQuery must also work if there where more buttons..Fiddle link below and the code i tried

$('button').each(function(){
   $('button').click(function(){
      find('input[type="text"]').val() = "0";
   });
});

[小提琴链接] http://jsfiddle.net/vineetgnair/1s22gcL5/

感谢大家的帮助.

推荐答案

这会起作用:

$('button').click(function(){
   $('input[type="text"]').val(0);
});

如果您只想重置字段,则:

If you want to just reset field then :

$('button').click(function(){
   $('input[type="text"]').val('');
});

这篇关于单击按钮清除输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆