How to clear all textboxs in a DIV using jQuery?

2020-06-17 06:40发布

I have some asp textboxs in a div container. I just want to clear those when i am clicking the CLEAR button.

I say common class 'text' for all textboxes and then wrote this jQuery

$(".text").text(""); 

It's not working ..

How to do this ? I need the most efficient code .

5条回答
We Are One
2楼-- · 2020-06-17 06:47

If you need to clear text boxes values alone, you can change the code like this:

$("#divID").find("input[type=text]").val('');  

or

$("#divID").find("input:text").val('');
查看更多
唯我独甜
3楼-- · 2020-06-17 06:51
$('a.clearButton').bind('click', function() {
    $('#divId input').val('');
});

Notes:

  1. You should use val() instead of text().

  2. You are asking for efficient code - and using class selector is not efficient.

    Either use id, or add tag name.

查看更多
We Are One
4楼-- · 2020-06-17 06:51

this will work successfully

$(':text').val("");    
查看更多
孤傲高冷的网名
5楼-- · 2020-06-17 07:05
$('#ClearButton').bind('click',function(){
$('#div1').Find('input[type=text]').val('');
});

or

$('#ClearButton').bind('click',function(){
$('#div1').Find('input:text').val('');
});
查看更多
疯言疯语
6楼-- · 2020-06-17 07:12
$('#yourcontainerid input:checked').removeAttr('checked');
查看更多
登录 后发表回答