如果需要实时完成,可以这样做:可以将其添加到 JS 文件的顶部: var inputChange = function (){ ($('input#photo').val().length === 0) { // Hide the element On keyup check the value of the input if length is 0 meaning empty hide the div otherwise show. $('div.sofdown').hide(); // Using hide() //Or using fadeOut(); $('div.sofdown').fadeOut(1000); } }//Initiate to hide the div if there is no text in input.inputChange();之后初始状态将是hidden这应该添加到JS文件的末尾$('input#photo').keyup(function() { //Call function inputChange();}