mozilla
Your Search Results

    Веб-Консоль Помощь

    This translation is incomplete. Please help translate this article from English.

    Команды

    Командная строка JavaScript, предоставляемая Веб-Консолью, предлагает несколько встроенных вспомогательных функций, которые делают определенные задачи проще.

    $()
    Ищет CSS-селектор, возвращая первый найденный элемент. Эквивалентно document.querySelector() или вызывается функция $, если таковая найдена на странице.
    $$()
    Looks up a CSS selector string, returning a list of DOM nodes that match. This is a shortcut for document.querySelectorAll().
    $0
    The currently-inspected element in the page.
    $_
    New in Firefox 39. Stores the result of the last expression executed in the console's command line. For example, if you type "2+2 <enter>", then "$_ <enter>", the console will print 4.
    $x()
    Evaluates an XPath expression and returns an array of matching nodes.
    keys()
    Given an object, returns a list of the keys (or property names) on that object. This is a shortcut for Object.keys.
    values()
    Given an object, returns a list of the values on that object; serves as a companion to keys().
    clear()
    Очищает область вывода консоли.
    inspect()
    Given an object, opens the object inspector for that object.
    pprint()
    Formats the specified value in a readable way; this is useful for dumping the contents of objects and arrays.
    help()
    Показывает текст помощи. На самом деле (вот восхитительный пример рекурсии) она приведет вас к этой странице.
    cd()
    Switch JavaScript evaluation context to a different iframe in the page. See working with iframes.
    copy()
    New in Firefox 38. Copy the argument to the clipboard. If the argument is a string, it's copied as-is. If the argument is a DOM node, its outerHTML is copied. Otherwise, JSON.stringify will be called on the argument, and the result will be copied to the clipboard.
    clearHistory()
    New in Firefox 39. Just like a normal command line, the console command line remembers the commands you've typed. Use this function to clear the console's command history.
    Please refer to the Console API for more information about logging from content.

    Examples

    Example: Looking at the contents of a DOM node

    Let's say you have a DOM node with the ID "title". In fact, this page you're reading right now has one, so you can open up the Web Console and try this right now.

    Let's take a look at the contents of that node by using the $() and inspect() functions:

    inspect($("#title"))

    This automatically opens up the object inspector, showing you the contents of the DOM node that matches the CSS selector "#title", which is of course the element with ID "title".

    Example: Dumping the contents of a DOM node

    That's well and good if you happen to be sitting at the browser exhibiting some problem, but let's say you're debugging remotely for a user, and need a look at the contents of a node. You can have your user open up the Web Console and dump the contents of the node into the log, then copy and paste it into an email to you, using the pprint() function:

    pprint($("#title"))
    

    This spews out the contents of the node so you can take a look. Of course, this may be more useful with other objects than a DOM node, but you get the idea.

    Метки документа и участники

    Contributors to this page: Aleksej, Igor_V_Belousov
    Обновлялась последний раз: Aleksej,