<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Demo</title>
</head>
<body>
</body>
</html>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
if ( $( '#nonexistent' ) ) {
console.log('test');
}
</script>
问题:
实际上我的页面中没有这样的id #nonexistent
,但是为什么这条线仍然运行:console.log('test');