我正在尝试评估输入字段中内容的长度。如果内容的长度为0,我想应用一些CSS样式。
When I remove the if statement, this function works on focus out. Can you see where I've gone wrong with my syntax?
$( "input" ).focusout(function() {
var n = $( "input" ).length;
if (n == 0) {
$( '.enteremail' ).css( "transform", "translateY(0px)");
}
});
最佳答案
您必须检查输入的值:
$('input').focusout(function() {
// Check the value of the affected ("this") input
var n = $(this).val().length;
if (n === 0) {
$('.enteremail').css('transform', 'translateY(0px)');
}
});
不是文档中输入字段的数量
关于javascript - focusout() 无法使用 jQuery 运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52701531/