开发者

Jquery clearing value for multiple text fields at once

开发者 https://www.devze.com 2023-03-04 06:04 出处:网络
I have 4 text fields in a form that I want to clear when clicking a div. I gave each text field a class class=\"1\" and am using this function to clear them.

I have 4 text fields in a form that I want to clear when clicking a div.

I gave each text field a class class="1" and am using this function to clear them.

开发者_如何学Go
$('#clear').click(function() {
    $(".1").val('');
});

This seems to work but I'm wondering if there's a better, standard way to do it.

Note: I don't want to clear the entire form.


Aside from that being an invalid class name (pretty sure they can't start with a number), this should be fine. I would however name the class in a more meaningful way.


Just be clear you shouldn't have css names start with a number to conform to the standard. But if you do manage to make that work you just might have to make your selector be slightly different and it should pick it up.

$("#clear").click(function() {
    $("input[class='1']").val("");
});
0

精彩评论

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