简体   繁体   English

使用jQuery,如果单击一个表单,如何清除表单上的所有文本框?

[英]Using jquery how can I clear all the text boxes on a form if I click in one?

I am trying to clear all the text boxes on a form if the user clicks on any one of them. 如果用户单击其中的任何一个,我将尝试清除表单上的所有文本框。 Basically I have some fields from a db from which to search as rows in a table. 基本上,我有数据库中的一些字段,可以从中搜索表中的行。 Then there is a radio button for each row. 然后每一行都有一个单选按钮。 I want to have it setup so that when the user clicks in a text box it all the other text boxes on the form must have their values set to ''. 我想要设置它,以便当用户在文本框中单击时,表单上的所有其他文本框必须将其值设置为''。

So far this code works to clear the current text box: 到目前为止,此代码可以清除当前文本框:

    $(document).ready(function() {
        $('.novalue').focus(function() {
            $(this).val("");
        });
    });

All my text boxes in the table has the class="novalue" property. 我在表中的所有文本框都具有class =“ novalue”属性。 I just cannot figure out how to make it clear all and not just the one. 我只是想不出如何使所有事情变得清晰,而不仅仅是一个。

You were very close. 你很亲近 But you don't want to reset $(this) , but all input fields of that class: 但是您不想重置$(this) ,而是要重置该类的所有输入字段:

$(document).ready(function() {
    $('.novalue').focus(function() {
        $('.novalue').val("");
    });
});

You can use this code: 您可以使用以下代码:

http://jsfiddle.net/V7j3b/1/ http://jsfiddle.net/V7j3b/1/

$(document).ready(function () {
    $('.novalue').focus(function () {
        $('.novalue').val("");
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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