For your HTML, use this:
<input type='search' id='search' disabled="disabled">
<button id='submit'>Submit</button>
<button id='reset'>Reset</button>
Notice that of [disabled="disabled"], then your JavaScript use:
<script>
(function() {
var searchInput = $("#search");
var searchAttr = $("#search").attr("disabled");
$( "#submit" ).click(function() {
$('body').prepend('<div class= "item" ></div>');
if ( $('.item').length === 0 ) { // Use triple equals for exact type check
searchInput.attr( "disabled", searchAttr );
} else{
searchInput.removeAttr("disabled");
}
});
$('#reset').on('click', function() {
$('.item').remove();
searchInput.attr( "disabled", searchAttr );
})
})();
</script>
This should work.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…