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>
유효한 html로 모든 ID가 고유해야하므로 '$ (data) .find ('# content ')'를 사용할 필요가 없다는 것을 언급하고 싶습니다. 단지'$ ('# ' content ')' – nathanjosiah