开发者

How to clear all textboxs in a DIV using jQuery?

开发者 https://www.devze.com 2022-12-21 05:23 出处:网络
I have some asp textboxs in a div contain开发者_开发技巧er. I just want to clear those when i am clicking theCLEAR button.

I have some asp textboxs in a div contain开发者_开发技巧er. 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 .


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('');


$('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.


$('#yourcontainerid input:checked').removeAttr('checked');


this will work successfully

$(':text').val("");    


$('#ClearButton').bind('click',function(){
$('#div1').Find('input[type=text]').val('');
});

or

$('#ClearButton').bind('click',function(){
$('#div1').Find('input:text').val('');
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号