简体   繁体   English

清空除一个字段外的所有字段

[英]Empty all fields except one

I am trying to clear all text except one field using js 我正在尝试使用js清除除一个字段之外的所有文本

Used below code : 使用以下代码:

$('input[type=text]').each(function(){
    if ($(this).hasClass('.isMobile').length < 0) {
        $(this).val('');
    }
});

$(this).hasClass('.isMobile').length used this to check particular field has some class. $(this).hasClass('.isMobile').length用于检查特定字段是否具有某些类。

But $(this).hasClass('.isMobile').length showing undefined every time. 但是$(this).hasClass('.isMobile').length每次都显示未定义。

You don't need a loop for that, you only need to narrow down your jQuery selector : 您不需要为此而循环,只需要缩小jQuery选择器的范围即可:

$('input[type=text].isMobile').val('');

If you want to exclude the input with the class isMobile instead : 如果要使用isMobile类排除输入,则:

$('input[type=text]:not(.isMobile)').val('');

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

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