使用Firebug的基本帮助

时间:2010-07-20 15:28:22

标签: jquery firebug

刚开始使用Firebug控制台。我有一个测试脚本,我将在下面发布。我打开Firebug控制台并键入$(“p”);这返回null。我的理解是它应该返回我的所有p元素,即p,p.foo,p,p#bar。可能是冲突,还是我只是错误地使用控制台?

<!DOCTYPE html>
<html>
<head>
  <title>Testing jQuery</title>
</head>

<body>
    <p>Hello World!</p>
    <p class="foo">Another paragraph, but this one has a class.</p>
    <p><span>This is a span inside a paragraph.</span></p>
    <p id="bar">Paragraph with an id.
    <span class="foo">And this sentence is in a span.</span>
    </p>

    <script type="text/javascript" src="http://www.google.com/jsapi"></script>
    <script type="text/javascript"
        google.load("jquery", "1.4.2");
    </script>
</body>
</html>

3 个答案:

答案 0 :(得分:2)

您使用的是ID选择器。如果你有一个带id的选择器你应该使用$(“ID”)。

你想要的是一系列css选择器 - &gt;那么你应该使用$$(“选择器”) - &gt;在你的情况下:$$(“p”)

可在此处找到更多信息

http://www.joehewitt.com/software/firebug/docs.php

我希望这有帮助:D

答案 1 :(得分:1)

您正确使用控制台。即使jQuery找不到任何结果,它也应该返回一个空对象,而不是null。

你可以console.log($);看看是否加载了jQuery?

这应该导致返回jQuery函数:

function ( selector, context ) {
    // The jQuery object is actually just the init constructor 'enhanced'
    return new jQuery.fn.init( selector, context );
}

答案 2 :(得分:0)

是的,你正确使用控制台,当我打开firebug并输入$("p")时,它会返回DOM中的everry p元素。