我通过在jQuery网站中添加条件来修改此代码,但无论怎么改,它总是进入第一个“ if”——如何才能修正这个错误?
<script>
/* attach a submit handler to the form */
$("#searchForm").submit(function(event) {
/* stop form from submitting normally */
event.preventDefault();
/* get some values from elements on the page: */
var $form = $( this ),
term = $form.find( 'input[name="s"]' ).val(),
url = $form.attr( 'action' );
/* Send the data using post and put the results in a div */
**//the condition doesn't work here. It always get into the first "if". Why?**
$.post( url, { s: term },
function( data ) {
if (var content = $( data ).find( '#content' )) {
console.log('One or more results were found');
} else {
console.log('no result');
}
}
);
});
</script>