gpt4 book ai didi

javascript - 如何设置为未定义或删除某些部分

转载 作者:行者123 更新时间:2023-11-29 10:10:34 25 4
gpt4 key购买 nike

我尝试了几个小时,但找不到删除或未定义以下代码部分的解决方案:

$(document).ready(function() {
// Generate a simple captcha
function randomNumber(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
};
$('#captchaOperation').html([randomNumber(1, 100), '+', randomNumber(1, 200), '='].join(' '));

$('#defaultForm').bootstrapValidator({
message: 'This value is not valid',
fields: {
field1: {
message: 'The field is not valid',
validators: {
notEmpty: {
message: 'The field is required and can\'t be empty'
},
stringLength: {
min: 1,
max: 30,
message: 'The field must be more than 1 and less than 30 characters long'
},
regexp: {
regexp: /^[a-zA-Z0-9_\.]+$/,
message: 'The field can only consist of alphabetical, number, dot and underscore'
}

}
},
field2: {
message: 'The field is not valid',
validators: {
notEmpty: {
message: 'The field is required and can\'t be empty'
},
stringLength: {
min: 1,
max: 30,
message: 'The field must be more than 1 and less than 30 characters long'
},
regexp: {
regexp: /^[a-zA-Z0-9_\.]+$/,
message: 'The field can only consist of alphabetical, number, dot and underscore'
}

}
},
captcha: {
validators: {
callback: {
message: 'Wrong answer',
callback: function(value, validator) {
var items = $('#captchaOperation').html().split(' '), sum = parseInt(items[0]) + parseInt(items[2]);
return value == sum;
}
}
}
}
}
});
});

在上面的脚本中,我想删除 field1:{................},为此以下内容将完成这项工作:

delete fields.field1; or
fields.field1 = undefined;

但我无法理解如何使用这些代码。

最佳答案

首先您需要将对象存储在变量中:

var validation = {
message: 'This value is not valid',
fields: {
field1: {
message: 'The field is not valid',
validators: {
notEmpty: {
message: 'The field is required and can\'t be empty'
},
stringLength: {
min: 1,
max: 30,
message: 'The field must be more than 1 and less than 30 characters long'
},
regexp: {
regexp: /^[a-zA-Z0-9_\.]+$/,
message: 'The field can only consist of alphabetical, number, dot and underscore'
}

}
},
field2: {
message: 'The field is not valid',
validators: {
notEmpty: {
message: 'The field is required and can\'t be empty'
},
stringLength: {
min: 1,
max: 30,
message: 'The field must be more than 1 and less than 30 characters long'
},
regexp: {
regexp: /^[a-zA-Z0-9_\.]+$/,
message: 'The field can only consist of alphabetical, number, dot and underscore'
}

}
},
captcha: {
validators: {
callback: {
message: 'Wrong answer',
callback: function(value, validator) {
var items = $('#captchaOperation').html().split(' '), sum = parseInt(items[0]) + parseInt(items[2]);
return value == sum;
}
}
}
}
}
};

然后你可以删除它:

delete validation.fields.field1;

关于javascript - 如何设置为未定义或删除某些部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34307816/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com