我从https://github.com/jquery/sizzle下载了sizzle.js
我的代码是:

<!DOCTYPE html>
<html>
<head>
    <title>Demo</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script src="sizzle.js" type="text/javascript"></script>
    <script type="text/javascript">
        window.onload=load;
        function load(){
            alert(Sizzle("#test"));
            alert(Sizzle("#test").innerHTML);
        }
    </script>
</head>
<body>
<div id="test">abc</div>
</body>
</html>

但是警告“[object]”,“undefined”,请告诉我我的代码出了什么问题?

最佳答案

Sizzle()函数返回匹配元素的数组。因此,如果您知道只有一个匹配元素(如果您按ID选择,则应该有一个),请尝试:

alert(Sizzle("#test")[0].innerHTML);

10-05 23:13