我正在尝试通过编写代码来提高自己。我可以理解它的正常状态,没有任何问题。在下面的示例代码中,嵌套了 jquery、值读取、值分配和 if-else 查询。我无法以有意义的可读方式获取代码。任何人都可以以简单的扩展可读格式编写下面的代码吗?
$('.input-required input, .input-required select, .input-required textarea').on('focusin keyup', function () {
var inputSpan = $(this).parent().find('span').text();
$(this).val() != inputSpan && '' != $(this).val() && $(this).parent().find('span').addClass('input-style-1-active').removeClass('input-style-1-inactive'),
'' === $(this).val() && $(this).parent().find('span').removeClass('input-style-1-inactive input-style-1-active')
});
$('.input-required input, .input-required select, .input-required textarea').on('focusout', function () {
$(this).parent().find('span').text();
'' === $(this).val() && $(this).parent().find('span').removeClass('input-style-1-inactive input-style-1-active'),
$(this).parent().find('span').addClass('input-style-1-inactive')
});
第一个代码块的扩展版本正确如下?
$('.input-required input, .input-required select, .input-required textarea').on('focusin keyup', function () {
var inputSpan = $(this).parent().find('span').text();
if(($(this).val() != inputSpan) && ('' != $(this).val())){
$(this).parent().find('span').addClass('input-style-1-active').removeClass('input-style-1-inactive');
}else{
$(this).parent().find('span').removeClass('input-style-1-inactive input-style-1-active');
}
});